线城池通用方法汇总

最近业务中经常用到线城池,我在这里持续完善线城池中我使用到的线程方法。

import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import java.util.List;
import java.util.concurrent.*;

/**
 * 类描述:线城池工具类
 *
 * @ClassName ThreadToolUtil
 */
public class ThreadToolUtil {
    
    
    /*异步查询线程池*/
    public static ExecutorService selectData = new ThreadPoolExecutor(
            5,  //核心线程池大小
            10, //最大线程池大小
            1000L, //线程最大空闲时间
            TimeUnit.MILLISECONDS, //时间单位
            //线程等待队列
            new LinkedBlockingQueue<Runnable>(1024),
            new CustomizableThreadFactory("数据查询线程"),
            //拒绝策略,这里直接抛出异常
            new ThreadPoolExecutor.AbortPolicy()
    );


    /**
     * 批量执行线程
     *
     * @param executorService 线程池
     * @param theadList       线程列表
     * @return void
     */
    public static void listTheadExecute(ExecutorService executorService, List<Thread> theadList) {
    
    
        for (Thread thread : theadList
        ) {
    
    
            executorService.execute(thread);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43487532/article/details/127906524