Created
August 1, 2013 15:58
-
-
Save tigawa/6132713 to your computer and use it in GitHub Desktop.
ThreadTest5.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
public class ThreadTest5 { | |
public static void main(String[] args) { | |
System.out.println("Entering main"); | |
ExecutorService exec = Executors.newSingleThreadExecutor(); | |
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(); | |
} | |
} | |
}); | |
} | |
//シャットダウンを実行します。 | |
//以前に送信したタスクは実行しますが、新規タスクは受け入れません。 | |
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