1.修改创建线程池返回类

2.add Test
This commit is contained in:
wenlianggong 2024-07-01 20:38:53 +08:00
parent b587caca0d
commit 5474735197
2 changed files with 14 additions and 2 deletions

View File

@ -178,7 +178,7 @@ public class ThreadUtil {
* @author luozongle
* @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,
(isBlocked ? RejectPolicy.BLOCK : RejectPolicy.ABORT).getValue());
}
@ -198,7 +198,7 @@ public class ThreadUtil {
* @author luozongle
* @since 5.8.0
*/
public static ExecutorService newFixedExecutor(final int nThreads,
public static ThreadPoolExecutor newFixedExecutor(final int nThreads,
final int maximumQueueSize,
final String threadNamePrefix,
final RejectedExecutionHandler handler) {

View File

@ -28,6 +28,18 @@ import java.util.concurrent.atomic.AtomicInteger;
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
public void testNewExecutorByBlockingCoefficient(){
ThreadPoolExecutor executor = ThreadUtil.newExecutorByBlockingCoefficient(0.5f);