ExecutorService service = Executors.newCachedThreadPool();
service.execute(new Runnable() {
@Override
public void run() {
}
});
Future<Integer> result = service.submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return 1;
}
});
以newCachedThreadPool()
为例
所以问题的关键是ThreadPoolExecutor
默认的饱和策略是AbortPolicy
基本的任务排队方法有三种
- 无界队列
- 有界队列
- 同步移交
- beforeExecute
- afterExecute
- terminated