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 40788
Collapse All | Expand All

(-)a/openide.util/src/org/openide/util/RequestProcessor.java (-2 / +20 lines)
Lines 1419-1424 Link Here
1419
                Item scheduled = this.item;
1419
                Item scheduled = this.item;
1420
                if (scheduled != null && scheduled.getTask() == this) {
1420
                if (scheduled != null && scheduled.getTask() == this) {
1421
                    // do not mark as finished, we are scheduled for future
1421
                    // do not mark as finished, we are scheduled for future
1422
                    if (time != 0) {
1423
                        long reschedule = time - System.currentTimeMillis();
1424
                        if (reschedule < 0) {
1425
                            reschedule = 0;
1426
                        }
1427
                        time = 0;
1428
                        schedule(reschedule);
1429
                    }
1422
                } else {
1430
                } else {
1423
                    notifyFinished();
1431
                    notifyFinished();
1424
                }
1432
                }
Lines 1460-1466 Link Here
1460
                throw new IllegalStateException("RequestProcessor already stopped!"); // NOI18N
1468
                throw new IllegalStateException("RequestProcessor already stopped!"); // NOI18N
1461
            }
1469
            }
1462
1470
1463
            time = System.currentTimeMillis() + delay;
1471
            long localTime = System.currentTimeMillis() + delay;
1464
1472
1465
            final Item localItem;
1473
            final Item localItem;
1466
1474
Lines 1470-1483 Link Here
1470
                }
1478
                }
1471
                notifyRunning();
1479
                notifyRunning();
1472
1480
1481
                boolean scheduleLater = false;
1473
                if (item != null) {
1482
                if (item != null) {
1474
                    item.clear(null);
1483
                    scheduleLater = !item.clear(null) || time > 0;
1475
                }
1484
                }
1476
1485
1486
                time = localTime;
1487
1477
                item = enableStackTraces ?
1488
                item = enableStackTraces ?
1478
                    new SlowItem(this, RequestProcessor.this) :
1489
                    new SlowItem(this, RequestProcessor.this) :
1479
                    new FastItem(this, RequestProcessor.this);
1490
                    new FastItem(this, RequestProcessor.this);
1491
1492
                if (scheduleLater) {
1493
                    return;
1494
                }
1495
1480
                localItem = item;
1496
                localItem = item;
1497
1481
            }
1498
            }
1482
1499
1483
            if (delay == 0) { // Place it to pending queue immediatelly
1500
            if (delay == 0) { // Place it to pending queue immediatelly
Lines 1944-1949 Link Here
1944
                    synchronized (current.processorLock) {
1961
                    synchronized (current.processorLock) {
1945
                        todo = current.askForWork(this, debug);
1962
                        todo = current.askForWork(this, debug);
1946
                        if (todo == null) break;
1963
                        if (todo == null) break;
1964
                        todo.time = 0;
1947
                    }
1965
                    }
1948
                    setPrio(todo.getPriority());
1966
                    setPrio(todo.getPriority());
1949
1967
(-)a/openide.util/test/unit/src/org/openide/util/RequestProcessorTest.java (+37 lines)
Lines 42-47 Link Here
42
package org.openide.util;
42
package org.openide.util;
43
43
44
import java.lang.ref.*;
44
import java.lang.ref.*;
45
import java.util.concurrent.atomic.AtomicInteger;
45
import java.util.logging.Handler;
46
import java.util.logging.Handler;
46
import java.util.logging.LogRecord;
47
import java.util.logging.LogRecord;
47
import java.util.logging.Level;
48
import java.util.logging.Level;
Lines 90-95 Link Here
90
            ).initCause(ex);
91
            ).initCause(ex);
91
        }
92
        }
92
    }
93
    }
94
95
    public void testNonParallelReSchedule() throws Exception {
96
        final AtomicInteger counter = new AtomicInteger();
97
        final AtomicInteger peek = new AtomicInteger();
98
        peek.set(1);
99
100
        class R implements Runnable {
101
102
            @Override
103
            public void run() {
104
                try {
105
                    int cnt = counter.incrementAndGet();
106
                    Thread.sleep(200);
107
                    int now = counter.get();
108
                    if (now > peek.get()) {
109
                        peek.set(now);
110
                    }
111
                    counter.decrementAndGet();
112
                } catch (InterruptedException ex) {
113
                    throw new RuntimeException(ex);
114
                }
115
            }
116
        }
117
        R run = new R();
118
        RequestProcessor RP = new RequestProcessor("testNonParallelReSchedule", 20);
119
        RequestProcessor.Task task = RP.create(run);
120
        for (int i = 0; i < 20; i++) {
121
            task.schedule(0);
122
            Thread.sleep(10);
123
        }
124
        for (int i = 0; i < 50; i++) {
125
            task.waitFinished();
126
        }
127
128
        assertEquals("At most one task at once", 1, peek.get());
129
    }
93
    
130
    
94
    
131
    
95
    /** A test to check that objects are executed in the right order.
132
    /** A test to check that objects are executed in the right order.

Return to bug 40788