Difference between executor.submit and executor.execute
execute(Runnable) does not return anything.
However, submit(Callable) returns a Future object which allows a way for you to programatically cancel the running thread later as well as get the T that is returned when the Callable completes. See JavaDoc of Future for more details
Future<?> future = executor.submit(longRunningJob);
...
//long running job is taking too long
future.cancel(true);
Moreover, if future.get() == null and doesn’t throw any exception then Runnable executed successfully
https://stackoverflow.com/questions/18730290/difference-between-executor-submit-and-executor-execute-in-this-code-in-java
还没有评论,来说两句吧...