Skip to content

Commit d01e3d6

Browse files
committed
update Test2
1 parent a52510f commit d01e3d6

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/main/java/threadDev/Test2.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@ public static void main(String[] args) {
1212
@Override
1313
public void run() {
1414
try {
15-
for (; ; ) {}
15+
while (!Thread.currentThread().isInterrupted()) {
16+
for (; ; ) {
17+
System.out.println(
18+
"--> Thread name : "
19+
+ Thread.currentThread().getName()
20+
+ ", id = "
21+
+ Thread.currentThread().getId());
22+
System.out.println("i = ");
23+
}
24+
}
25+
26+
// for (; ; ) {
27+
// System.out.println("i = ");
28+
// }
29+
// for (int i = 0; i < 10; i++) {
30+
// System.out.println("i = " + i);
31+
// }
1632

1733
} finally {
1834
System.out.println("FINALLY");
@@ -26,12 +42,19 @@ public void run() {
2642
try {
2743
future.get(3, TimeUnit.SECONDS);
2844
} catch (TimeoutException e) {
45+
46+
System.out.println(">>> (before) future.cancel");
2947
boolean c = future.cancel(true);
48+
System.out.println(">>> (after) future.cancel");
49+
3050
System.out.println("Timeout " + c);
3151
} catch (InterruptedException | ExecutionException e) {
3252
System.out.println("interrupted");
53+
} finally {
54+
System.out.println("executor.shutdown");
55+
executor.shutdown();
56+
System.out.println("END");
3357
}
34-
System.out.println("END");
3558
}
36-
59+
3760
}

0 commit comments

Comments
 (0)