Skip to content

Commit e49aeba

Browse files
hansonrhansonr
authored andcommitted
https://github.com/BobHanson/java2script/issues/205
ThreadPoolExecutor not waiting one microtick to initiate jobs -- resulting in unpredictable, incomplete handling of 0-delay tasks. Minimum set to 1 ms. See test.Test_Exect
1 parent 4b30390 commit e49aeba

File tree

7 files changed

+5
-5
lines changed

7 files changed

+5
-5
lines changed
-396 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20210114181553
1+
20210115052741
-396 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20210114181553
1+
20210115052741
-396 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/util/concurrent/ScheduledThreadPoolExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private void delayedExecute(RunnableScheduledFuture<?> task) {
312312
task.run();
313313
}
314314

315-
}), Math.max(-1, (int) task.getDelay(TimeUnit.MILLISECONDS)), 0), task);
315+
}), Math.max(1, (int) task.getDelay(TimeUnit.MILLISECONDS)), 0), task);
316316

317317
} else /** @j2sIgnore */
318318
{

sources/net.sf.j2s.java.core/src/test/Test_Exec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Test_Exec implements StateMachine {
1818
StateHelper helper;
1919
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
2020
static Set<Integer> pending = new HashSet<>();
21-
int N = 10, j = 0;
21+
int N = 1000, j = 0;
2222

2323
public static void main(String[] args) {
2424
new Test_Exec();
@@ -44,7 +44,7 @@ public boolean stateLoop() {
4444
System.out.println(pending.size());
4545
executor.submit(() -> {
4646
pending.remove(i);
47-
System.out.println(pending.size());
47+
System.out.println(i + " " + pending.size());
4848
if (pending.size() == 0) {
4949
helper.next(2);
5050
}

0 commit comments

Comments
 (0)