Skip to content

Instantly share code, notes, and snippets.

@tigawa
Created August 1, 2013 16:36
Show Gist options
  • Save tigawa/6133035 to your computer and use it in GitHub Desktop.
Save tigawa/6133035 to your computer and use it in GitHub Desktop.
ThreadTest6.java
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadTest6 {
public static void main(String[] args) {
System.out.println("Entering main");
ExecutorService exec = Executors.newCachedThreadPool();
for (int i = 0; i < 10; i++) {
exec.execute(new Runnable() {
public void run() {
try {
System.out.println("Run!! - "
+ Thread.currentThread().getId());
Thread.sleep(1 * 3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
Thread.currentThread().getThreadGroup().list();
}
//シャットダウンを実行します。
//以前に送信したタスクは実行しますが、新規タスクは受け入れません。
exec.shutdown();
System.out.println("Exit main");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment