This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 165862
Collapse All | Expand All

(-)a/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java (-1 / +1 lines)
Lines 89-95 Link Here
89
    static final long serialVersionUID = -98124752801761145L;
89
    static final long serialVersionUID = -98124752801761145L;
90
90
91
    /** One request proccesor shared for all instances of JarFileSystem*/
91
    /** One request proccesor shared for all instances of JarFileSystem*/
92
    private static RequestProcessor req = new RequestProcessor("JarFs - modification watcher"); // NOI18N
92
    private static RequestProcessor req = new RequestProcessor("JarFs - modification watcher", 1, false, false); // NOI18N
93
93
94
    /** Controlls the LocalFileSystem's automatic refresh.
94
    /** Controlls the LocalFileSystem's automatic refresh.
95
    * If the refresh time interval is set from the System.property, than this value is used.
95
    * If the refresh time interval is set from the System.property, than this value is used.
(-)a/openide.util/apichanges.xml (+15 lines)
Lines 49-54 Link Here
49
    <apidef name="actions">Actions API</apidef>
49
    <apidef name="actions">Actions API</apidef>
50
</apidefs>
50
</apidefs>
51
<changes>
51
<changes>
52
    <change id="enableStackTraces">
53
        <api name="util"/>
54
        <summary>Added constructor <code>RequestProcessor(String name, int throughput, boolean interruptThread, boolean enableStackTraces)</code></summary>
55
        <version major="7" minor="24"/>
56
        <date day="8" month="6" year="2009"/>
57
        <author login="rmichalsky"/>
58
        <compatibility addition="yes"/>
59
        <description>
60
            <p>
61
                Newly added constructor allows to disable (slow) filling stack traces before posting each task. 
62
            </p>
63
        </description>
64
        <class package="org.openide.util" name="RequestProcessor"/>
65
        <issue number="165862"/>
66
    </change>
52
    <change id="ImageUtilities.loadImageIcon">
67
    <change id="ImageUtilities.loadImageIcon">
53
        <api name="util"/>
68
        <api name="util"/>
54
        <summary>Added <code>loadImageIcon(String resource, boolean localized)</code></summary>
69
        <summary>Added <code>loadImageIcon(String resource, boolean localized)</code></summary>
(-)a/openide.util/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
module.jar.dir=lib
42
module.jar.dir=lib
43
cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
43
cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
44
44
45
spec.version.base=7.23.0
45
spec.version.base=7.24.0
46
46
47
# For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4:
47
# For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4:
48
48
(-)a/openide.util/src/org/openide/util/RequestProcessor.java (-24 / +64 lines)
Lines 173-178 Link Here
173
    
173
    
174
    /** support for interrupts or not? */
174
    /** support for interrupts or not? */
175
    private boolean interruptThread;
175
    private boolean interruptThread;
176
    /** fill stacktraces when task is posted? */
177
    private boolean enableStackTraces;
176
178
177
    /** Creates new RequestProcessor with automatically assigned unique name. */
179
    /** Creates new RequestProcessor with automatically assigned unique name. */
178
    public RequestProcessor() {
180
    public RequestProcessor() {
Lines 221-229 Link Here
221
     * @since 6.3
223
     * @since 6.3
222
     */
224
     */
223
    public RequestProcessor(String name, int throughput, boolean interruptThread) {
225
    public RequestProcessor(String name, int throughput, boolean interruptThread) {
226
        this(name, throughput, interruptThread, SLOW);
227
    }
228
229
    /** Creates a new named <code>RequestProcessor</code> that allows to disable stack trace filling.
230
     * By default, when assertions are on, each task posted on <code>RequestProcessor</code> stores
231
     * the stack trace at the time of posting. When an exception is later thrown from the task,
232
     * it allows to print not only stack trace of the task but also stack trace of the code that posted it.
233
     * However this may be a performance bottleneck in cases when hundreds of short task are scheduled.
234
     * This constructor then allows to create <code>RequestProcessor</code> which never stores stack traces
235
     * at the time of posting.
236
     * <p>
237
     * See constructor {@link #RequestProcessor(String, int, boolean)} for details of <code>interruptThread</code>
238
     * parameter.
239
     * </p>
240
     * @param name the name to use for the request processor thread
241
     * @param throughput the maximal count of requests allowed to run in parallel
242
     * @param interruptThread true if {@link RequestProcessor.Task#cancel} shall interrupt the thread
243
     * @param enableStackTraces <code>false</code> when request processor should not fill stack traces when task is posted.
244
     *              Default is <code>true</code> when assertions are enabled, <code>false</code> otherwise.
245
     * @since 7.24
246
     */
247
    public RequestProcessor(String name, int throughput, boolean interruptThread, boolean enableStackTraces) {
224
        this.throughput = throughput;
248
        this.throughput = throughput;
225
        this.name = (name != null) ? name : ("OpenIDE-request-processor-" + (counter++));
249
        this.name = (name != null) ? name : ("OpenIDE-request-processor-" + (counter++));
226
        this.interruptThread = interruptThread;
250
        this.interruptThread = interruptThread;
251
        this.enableStackTraces = enableStackTraces;
227
    }
252
    }
228
    
253
    
229
    
254
    
Lines 627-633 Link Here
627
                    item.clear(null);
652
                    item.clear(null);
628
                }
653
                }
629
654
630
                item = new Item(this, RequestProcessor.this);
655
                item = enableStackTraces ?
656
                    new SlowItem(this, RequestProcessor.this) :
657
                    new FastItem(this, RequestProcessor.this);
631
                localItem = item;
658
                localItem = item;
632
            }
659
            }
633
660
Lines 813-820 Link Here
813
    /* One item representing the task pending in the pending queue */
840
    /* One item representing the task pending in the pending queue */
814
    private static class Item extends Exception {
841
    private static class Item extends Exception {
815
        private final RequestProcessor owner;
842
        private final RequestProcessor owner;
816
        private Object action;
843
        Object action;
817
        private boolean enqueued;
844
        boolean enqueued;
818
        String message;
845
        String message;
819
846
820
        Item(Task task, RequestProcessor rp) {
847
        Item(Task task, RequestProcessor rp) {
Lines 849-879 Link Here
849
            return getTask().getPriority();
876
            return getTask().getPriority();
850
        }
877
        }
851
878
852
        @Override
853
        public Throwable fillInStackTrace() {
854
            if (SLOW) {
855
                Throwable ret = super.fillInStackTrace();
856
                StackTraceElement[] arr = ret.getStackTrace();
857
                for (int i = 1; i < arr.length; i++) {
858
                    if (arr[i].getClassName().startsWith("java.lang")) {
859
                        continue;
860
                    }
861
                    if (arr[i].getClassName().startsWith(RequestProcessor.class.getName())) {
862
                        continue;
863
                    }
864
                    ret.setStackTrace(Arrays.asList(arr).subList(i - 1, arr.length).toArray(new StackTraceElement[0]));
865
                    break;
866
                }
867
                return ret;
868
            } else {
869
                return this;
870
            }
871
        }
872
873
        public @Override String getMessage() {
879
        public @Override String getMessage() {
874
            return message;
880
            return message;
875
        }
881
        }
876
882
883
    }
884
885
    private static class FastItem extends Item {
886
        FastItem(Task task, RequestProcessor rp) {
887
            super(task, rp);
888
        }
889
890
        @Override
891
        public Throwable fillInStackTrace() {
892
            return this;
893
        }
894
    }
895
    private static class SlowItem extends Item {
896
897
        SlowItem(Task task, RequestProcessor rp) {
898
            super(task, rp);
899
        }
900
901
        @Override
902
        public Throwable fillInStackTrace() {
903
            Throwable ret = super.fillInStackTrace();
904
            StackTraceElement[] arr = ret.getStackTrace();
905
            for (int i = 1; i < arr.length; i++) {
906
                if (arr[i].getClassName().startsWith("java.lang")) {
907
                    continue;
908
                }
909
                if (arr[i].getClassName().startsWith(RequestProcessor.class.getName())) {
910
                    continue;
911
                }
912
                ret.setStackTrace(Arrays.asList(arr).subList(i - 1, arr.length).toArray(new StackTraceElement[0]));
913
                break;
914
            }
915
            return ret;
916
        }
877
    }
917
    }
878
918
879
    //------------------------------------------------------------------------------
919
    //------------------------------------------------------------------------------
(-)a/openide.util/test/unit/src/org/openide/util/RequestProcessorTest.java (-1 / +75 lines)
Lines 45-50 Link Here
45
import java.util.logging.Handler;
45
import java.util.logging.Handler;
46
import java.util.logging.LogRecord;
46
import java.util.logging.LogRecord;
47
import java.util.logging.Level;
47
import java.util.logging.Level;
48
import java.util.logging.Logger;
48
import junit.framework.Test;
49
import junit.framework.Test;
49
import org.openide.ErrorManager;
50
import org.openide.ErrorManager;
50
import org.netbeans.junit.*;
51
import org.netbeans.junit.*;
Lines 1346-1352 Link Here
1346
            x.notifyAll();
1347
            x.notifyAll();
1347
        }
1348
        }
1348
    }
1349
    }
1349
    
1350
1351
    private static class TestHandler extends Handler {
1352
        boolean stFilled = false;
1353
        boolean exceptionCaught = false;
1354
1355
        @Override
1356
        public void publish(LogRecord rec) {
1357
            if (rec.getThrown() != null) {
1358
                for (StackTraceElement elem : rec.getThrown().getStackTrace()) {
1359
                    if (elem.getMethodName().contains("testStackTraceFillingDisabled")) {
1360
                        stFilled = true;
1361
                        break;
1362
                    }
1363
                }
1364
                exceptionCaught = true;
1365
            }
1366
        }
1367
1368
        public void clear() {
1369
            stFilled = false;
1370
            exceptionCaught = false;
1371
        }
1372
1373
        @Override
1374
        public void flush() {
1375
        }
1376
1377
        @Override
1378
        public void close() throws SecurityException {
1379
        }
1380
    }
1381
1382
    public void testStackTraceFillingDisabled() throws InterruptedException {
1383
        boolean ea = false;
1384
        assert (ea = true);
1385
        assertTrue("Test must be run with enabled assertions", ea);
1386
        Logger l = RequestProcessor.logger();
1387
        TestHandler handler = new TestHandler();
1388
        l.addHandler(handler);
1389
        try {
1390
            RequestProcessor rp = new RequestProcessor("test rp #1", 1);
1391
            Task t = rp.post(new Runnable() {
1392
1393
                public void run() {
1394
                    throw new RuntimeException("Testing filled stacktrace");
1395
                }
1396
            });
1397
//            t.waitFinished(); // does not work, thread gets notified before the exception is logged
1398
            int timeout = 0;
1399
            while (! handler.exceptionCaught && timeout++ < 100) {
1400
                Thread.sleep(50);
1401
            }
1402
            assertTrue("Waiting for task timed out", timeout < 100);
1403
            assertTrue("Our testing method not found in stack trace", handler.stFilled);
1404
1405
            handler.clear();
1406
            timeout = 0;
1407
            rp = new RequestProcessor("test rp #2", 1, false, false);
1408
            t = rp.post(new Runnable() {
1409
1410
                public void run() {
1411
                    throw new RuntimeException("Testing 'short' stacktrace");
1412
                }
1413
            });
1414
            while (! handler.exceptionCaught && timeout++ < 100) {
1415
                Thread.sleep(50);
1416
            }
1417
            assertTrue("Waiting for task timed out", timeout < 100);
1418
            assertFalse("Our testing method found in stack trace", handler.stFilled);
1419
        } finally {
1420
            l.removeHandler(handler);
1421
        }
1422
    }
1423
1350
    private static void doGc (int count, Reference toClear) {
1424
    private static void doGc (int count, Reference toClear) {
1351
        java.util.ArrayList<byte[]> l = new java.util.ArrayList<byte[]> (count);
1425
        java.util.ArrayList<byte[]> l = new java.util.ArrayList<byte[]> (count);
1352
        while (count-- > 0) {
1426
        while (count-- > 0) {

Return to bug 165862