execute方法
submit方法
提交任务task,用返回值Future获得任务执行结果。
Future 用于主线程接受线程池中线程的返回结果。
ExecutorService executorService = Executors.newFixedThreadPool(2);
//提交第一个任务返回结果
Future<String> future = executorService.submit(new Callable<String>() {
@Override
public String call() throws Exception {
log.debug("running");
TimeUnit.SECONDS.sleep(1);
return "ok";
}
});
//提交第二个任务返回结果
Future<String> future2 = executorService.submit(()
标签:48,submit,任务,Future,线程,提交,executorService
From: https://blog.csdn.net/qq_36352889/article/details/139509095