!1232 修改创建线程池返回类

Merge pull request !1232 from 温良恭/v6-dev
This commit is contained in:
Looly 2024-07-02 01:00:17 +00:00 committed by Gitee
commit 64e4d9db7b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
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);