Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ExecutorService.submit和ExecutorService.execute之间有什么区别吗?_Java - Fatal编程技术网

Java ExecutorService.submit和ExecutorService.execute之间有什么区别吗?

Java ExecutorService.submit和ExecutorService.execute之间有什么区别吗?,java,Java,我认为这两种方法都会在将来的某个时间执行线程任务,为什么有两种方法?execute()不返回值,而submit()返回一个未来,可用于从执行的代码中获取返回值 execute()之所以存在,是因为它是ExecutorService扩展的Executor接口的一部分,很可能只有这样才能有一个非常简单的接口 submit返回一个Future,它允许您在任务完成后获取有关任务的信息

我认为这两种方法都会在将来的某个时间执行线程任务,为什么有两种方法?

execute()不返回值,而submit()返回一个未来,可用于从执行的代码中获取返回值


execute()之所以存在,是因为它是ExecutorService扩展的Executor接口的一部分,很可能只有这样才能有一个非常简单的接口

submit返回一个Future,它允许您在任务完成后获取有关任务的信息