!1230 修改 ThreadUtil.newExecutor 创建线程池返回类

Merge pull request !1230 from 温良恭/v5-dev
This commit is contained in:
Looly 2024-06-30 09:55:32 +00:00 committed by Gitee
commit a8e959c37c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 12 additions and 1 deletions

View File

@ -35,7 +35,7 @@ public class ThreadUtil {
* @param corePoolSize 同时执行的线程数大小
* @return ExecutorService
*/
public static ExecutorService newExecutor(int corePoolSize) {
public static ThreadPoolExecutor newExecutor(int corePoolSize) {
ExecutorBuilder builder = ExecutorBuilder.create();
if (corePoolSize > 0) {
builder.setCorePoolSize(corePoolSize);

View File

@ -4,8 +4,19 @@ import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
public class ThreadUtilTest {
@Test
public void newExecutorTest(){
ThreadPoolExecutor executor = ThreadUtil.newExecutor(5);
// 查询线程池 线程数
Assert.assertEquals(5, executor.getCorePoolSize());
}
@Test
public void executeTest() {
final boolean isValid = true;