求一个线程的实现方法
之前遇到一个线程的写法,可以把service的方法直接通过线程池异步执行。
只记得大概的写法了
//一个普通的service
public class Aservice {
public class b() {
.....
}
}
//这是一个线程池工具类,具体的代码忘记了,跪求大佬指点迷津
public class ExecutorUtil {
private final static Executor EXECUTOR = new ThreadPoolExecutor(8, 16, 5000, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(10), new ThreadPoolExecutor.CallerRunsPolicy());
public static void async(...) {
...
}
}
//使用方法大概是这样的,这样就可以直接把b方法异步执行
ExecutorUtil.EXECUTOR.async(()->b);