newSingleThreadExecutor 1つのみ
newFixedThreadPool 指定した数のthreadpool
newCachedThreadPool 60秒経つと廃棄されるthreadpool
newCachedThreadPool sample
public class Outer {
public static void main(String[] args) throws InterruptedException {
ExecutorService e = Executors.newCachedThreadPool();
for(int i=0;i<5;i++) {
e.submit(() -> {
System.out.println("a:" + Thread.currentThread().getId());
});
}
Thread.sleep(5000);
for(int i=0;i<5;i++) {
e.submit(() -> {
System.out.println("a:" + Thread.currentThread().getId());
});
}
Thread.sleep(70000);
for(int i=0;i<5;i++) {
e.submit(() -> {
System.out.println("a:" + Thread.currentThread().getId());
});
}
}
}
a:17
a:14
a:15
a:13
a:16
a:15
a:13
a:13
a:13
a:13
a:19
a:18
a:20
a:21
a:22