通常都是採用新建業務類implements Runnable接口的方式。
但是在service中這樣寫反而不便。
一種簡便的方法是在service中直接加入代碼:
private static ExecutorService threadPoolForFailed = Executors.newFixedThreadPool(10);
然後用execute或者submit方法,實測可用。
threadPoolForFailed.execute(new Runnable() {
@Override
public void run() {
// TODO
}
});
另外一種方法
通過Aware,較麻煩,在此不敘述。