自定義 ForkJoinPool 線程池,并消除classLoader加载失败的问题
添加 setContextClassLoader 写入classLoader 信息
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;
/**
* 自定義 ForkJoinPool 線程池
* @Description:ThreadPool
* @author:callen
* @date:2021年11月24日 下午2:02:50
*/
public interface ThreadPool {
/**
* Why this class?
* <br>because used ForkJoinPool is neeed classLoader
* <br>NO? this ClassLoader is null,some any class is register
* @Description:CustomForkJoinWorkerThread
* @author:callen
* @date:2021年11月24日 上午10:26:03
*/
static class CustomForkJoinWorkerThread extends ForkJoinWorkerThread {
CustomForkJoinWorkerThread(ForkJoinPool pool) {
super(pool);
setContextClassLoader(Thread.currentThread().getContextClassLoader());
}
}
ForkJoinPool joinPool = new ForkJoinPool(
ForkJoinPool.getCommonPoolParallelism(),
CustomForkJoinWorkerThread::new,
null,
false
);
}