mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
1.修改创建线程池返回类
2.add Test
This commit is contained in:
parent
b587caca0d
commit
5474735197
@ -178,7 +178,7 @@ public class ThreadUtil {
|
|||||||
* @author luozongle
|
* @author luozongle
|
||||||
* @since 5.8.0
|
* @since 5.8.0
|
||||||
*/
|
*/
|
||||||
public static ExecutorService newFixedExecutor(final int nThreads, final int maximumQueueSize, final String threadNamePrefix, final boolean isBlocked) {
|
public static ThreadPoolExecutor newFixedExecutor(final int nThreads, final int maximumQueueSize, final String threadNamePrefix, final boolean isBlocked) {
|
||||||
return newFixedExecutor(nThreads, maximumQueueSize, threadNamePrefix,
|
return newFixedExecutor(nThreads, maximumQueueSize, threadNamePrefix,
|
||||||
(isBlocked ? RejectPolicy.BLOCK : RejectPolicy.ABORT).getValue());
|
(isBlocked ? RejectPolicy.BLOCK : RejectPolicy.ABORT).getValue());
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ public class ThreadUtil {
|
|||||||
* @author luozongle
|
* @author luozongle
|
||||||
* @since 5.8.0
|
* @since 5.8.0
|
||||||
*/
|
*/
|
||||||
public static ExecutorService newFixedExecutor(final int nThreads,
|
public static ThreadPoolExecutor newFixedExecutor(final int nThreads,
|
||||||
final int maximumQueueSize,
|
final int maximumQueueSize,
|
||||||
final String threadNamePrefix,
|
final String threadNamePrefix,
|
||||||
final RejectedExecutionHandler handler) {
|
final RejectedExecutionHandler handler) {
|
||||||
|
@ -28,6 +28,18 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
public class ThreadUtilTest {
|
public class ThreadUtilTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNewFixedExecutor(){
|
||||||
|
|
||||||
|
ThreadPoolExecutor executor = ThreadUtil.newFixedExecutor(1, 2, "test-", true);
|
||||||
|
|
||||||
|
for (int i = 0; i < 20; i++) {
|
||||||
|
executor.execute(()->{
|
||||||
|
Console.log("执行任务1");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testNewExecutorByBlockingCoefficient(){
|
public void testNewExecutorByBlockingCoefficient(){
|
||||||
ThreadPoolExecutor executor = ThreadUtil.newExecutorByBlockingCoefficient(0.5f);
|
ThreadPoolExecutor executor = ThreadUtil.newExecutorByBlockingCoefficient(0.5f);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user