通常都是采用新建业务类implements Runnable接口的方式。
但是在service中这样写反而不便。
一种简便的方法是在service中直接加入代码:
private static ExecutorService threadPoolForFailed = Executors.newFixedThreadPool(10);
然后用execute或者submit方法,实测可用。
threadPoolForFailed.execute(new Runnable() {
@Override
public void run() {
// TODO
}
});
另外一种方法
通过Aware,较麻烦,在此不叙述。