|
|
@ -1,37 +0,0 @@ |
|
|
|
|
|
|
|
|
package com.thing.common.util.thread; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
|
import java.util.concurrent.ForkJoinPool; |
|
|
|
|
|
|
|
|
|
|
|
public class TBExecutors { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
*从ExecutorService分叉以提供线程轮询名称的方法 |
|
|
|
|
|
* |
|
|
|
|
|
* 创建一个线程池,保持足够的线程来支持 |
|
|
|
|
|
* 给定的并行性级别,并且可能使用多个队列来 |
|
|
|
|
|
* 减少争用。并行度级别对应于 |
|
|
|
|
|
* 最大数量的线程积极参与,或可 |
|
|
|
|
|
* 参与,任务处理。线程的实际数量可能 |
|
|
|
|
|
* 动态增长和收缩。偷工作的人不会 |
|
|
|
|
|
* 保证提交任务的顺序 |
|
|
|
|
|
* 执行。 |
|
|
|
|
|
* |
|
|
|
|
|
* @param parallelism the targeted parallelism level |
|
|
|
|
|
* @param namePrefix used to define thread name |
|
|
|
|
|
* @return the newly created thread pool |
|
|
|
|
|
* @throws IllegalArgumentException if {@code parallelism <= 0} |
|
|
|
|
|
* @since 1.8 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static ExecutorService newWorkStealingPool(int parallelism, String namePrefix) { |
|
|
|
|
|
return new ForkJoinPool(parallelism, |
|
|
|
|
|
new ForkJoinWorkerThreadFactory(namePrefix), |
|
|
|
|
|
null, true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static ExecutorService newWorkStealingPool(int parallelism, Class clazz) { |
|
|
|
|
|
return newWorkStealingPool(parallelism, clazz.getSimpleName()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|