Skip to content

Commit

Permalink
update Test2
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Jul 11, 2024
1 parent a52510f commit d01e3d6
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/main/java/threadDev/Test2.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,23 @@ public static void main(String[] args) {
@Override
public void run() {
try {
for (; ; ) {}
while (!Thread.currentThread().isInterrupted()) {
for (; ; ) {
System.out.println(
"--> Thread name : "
+ Thread.currentThread().getName()
+ ", id = "
+ Thread.currentThread().getId());
System.out.println("i = ");
}
}

// for (; ; ) {
// System.out.println("i = ");
// }
// for (int i = 0; i < 10; i++) {
// System.out.println("i = " + i);
// }

} finally {
System.out.println("FINALLY");
Expand All @@ -26,12 +42,19 @@ public void run() {
try {
future.get(3, TimeUnit.SECONDS);
} catch (TimeoutException e) {

System.out.println(">>> (before) future.cancel");
boolean c = future.cancel(true);
System.out.println(">>> (after) future.cancel");

System.out.println("Timeout " + c);
} catch (InterruptedException | ExecutionException e) {
System.out.println("interrupted");
} finally {
System.out.println("executor.shutdown");
executor.shutdown();
System.out.println("END");
}
System.out.println("END");
}

}

0 comments on commit d01e3d6

Please sign in to comment.