public class ThreadPoolExecutorDemo {
private static final ExecutorService pool = new ThreadPoolExecutor(4, 4, 10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(
10000), new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
System.out.println("Thread pool is FULL.Failed to submit the task to save call trace data.");
}
});
public static void test() {
for (int i = 0; i < 30000; i++) {
pool.submit(new Runnable() {
@Override
public void run() {
System.out.println(Thread.currentThread().getName() + "線程被執行");
}
});
}
}
public static void main(String[] args) {
ThreadPoolExecutorDemo.test();
}
}