ExecuterService submit
起因
重现
private static ExecutorService es = Executors.newSingleThreadExecutor();
public static void main(String[] args) throws InterruptedException, ExecutionException {
// test1
new Thread(() -> { throw new RuntimeException("in thread start");}).start();
// test2
es.execute(() -> { throw new RuntimeException("in execute");});
// test3
es.submit(() -> { throw new RuntimeException("in submit");});
// test4
Future<Object> future = es.submit(() -> { throw new RuntimeException("in submit"); });
Thread.sleep(1000);
future.get();
es.shutdown();
}原因
execute
submit
解决方案
方案1 - 选择 execute
方案2 - 从任务出发
方案3 - 从线程池出发
Last updated
