Skip to content

Commit b5c7e62

Browse files
authored
Merge pull request #206 from BobHanson/hanson1
Hanson1
2 parents f939cc6 + e49aeba commit b5c7e62

File tree

7 files changed

+66
-3
lines changed

7 files changed

+66
-3
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
{
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package test;
2+
3+
import java.awt.Font;
4+
import java.util.HashSet;
5+
import java.util.Set;
6+
import java.util.concurrent.Executors;
7+
import java.util.concurrent.Future;
8+
import java.util.concurrent.ScheduledExecutorService;
9+
10+
import javax.swing.JFrame;
11+
12+
import javajs.async.SwingJSUtils.StateHelper;
13+
import javajs.async.SwingJSUtils.StateMachine;
14+
15+
public class Test_Exec implements StateMachine {
16+
17+
18+
StateHelper helper;
19+
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
20+
static Set<Integer> pending = new HashSet<>();
21+
int N = 1000, j = 0;
22+
23+
public static void main(String[] args) {
24+
new Test_Exec();
25+
}
26+
27+
Test_Exec() {
28+
JFrame f = new JFrame();
29+
f.setSize(100,100);
30+
f.setVisible(true);
31+
helper = new StateHelper(this);
32+
helper.next(0);
33+
}
34+
35+
@Override
36+
public boolean stateLoop() {
37+
while (helper.isAlive()) {
38+
switch (helper.getState()) {
39+
case 0:
40+
helper.setState(1);
41+
for (int j = 0; j < N; j++) {
42+
int i = j;
43+
pending.add(i);
44+
System.out.println(pending.size());
45+
executor.submit(() -> {
46+
pending.remove(i);
47+
System.out.println(i + " " + pending.size());
48+
if (pending.size() == 0) {
49+
helper.next(2);
50+
}
51+
return;
52+
});
53+
}
54+
return false;
55+
case 2:
56+
System.out.println(pending);
57+
System.out.println("Test_Exec OK");
58+
return false;
59+
}
60+
}
61+
return false;
62+
}
63+
}

0 commit comments

Comments
 (0)