Skip to content

Commit 4b30390

Browse files
hansonrhansonr
authored andcommitted
Test_Exec - seems to miss some task removal tasks.
1 parent 9a4dd2e commit 4b30390

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
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 = 10, 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(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)