javaでシンプルなスレッドプールを実装する方法
javaコード:
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Startnews24_pool {
private static final ExecutorService threadPool = Executors.newFixedThreadPool(1);
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < 10000; i++) {
final int finalI = i;
Runnable r = new Runnable() {
@Override
public void run() {
System.out.println(String.valueOf(finalI)+":"+System.currentTimeMillis());
}
};
threadPool.submit(r);
Thread.currentThread().sleep(300L);
}
}
}