但是更多情况下,需要在另外的线程中运行任务,而非在主线程中运行任务,下面是一个稍微有意义一些的实现,它为每一个任务开启一个新的执行线程:public class SimpleExecutor implements Executor ...{
public void execute(Runnable r) ...{
r.run();①在提交时直接运行任务
}
}
class ThreadPerTaskExecutor implements Executor ...{
public void execute(Runnable r) ...{
new Thread(r).start();①在新的执行线程中执行任务
}
}
| 第1页: 概述 | 第2页: Executor接口 |
| 第3页: Spring对Executor所提供的抽象 |