- 任务架构:
- Callable和Runnable对比
Runnable | abstract void run() 不可抛出异常,不可获取异步执行结果 |
单一启动: 通过t.start()方法启动 | |
线程池提交: void threadPoolExecutor.executr(runnable) Future threadPoolExecutor.submit(runnable) | |
Callable | V call() throws Exception 可抛出异常,可获取异步执行结果f.get() |
单一启动: 通过new FutureTask(Callable<V> callable)的构造方法,获取Future的实现类f,通过f.start()方式启动 | |
线程池提交: Future threadPoolExecutor.submit(c) |
-
- Thread
实现了Runnable接口