All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.neko233.toolchain.common.base.ThreadPoolHelper233 Maven / Gradle / Ivy

package com.neko233.toolchain.common.base;

import com.neko233.toolchain.common.threadPool.ThreadFactoryByPrefixName;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author SolarisNeko
 * Date on 2023-01-28
 */
public class ThreadPoolHelper233 {

    public static ThreadPoolExecutor ioThreadPool(String name, final RejectedExecutionHandler rejectedExecutionHandler) {
        return new ThreadPoolExecutor(
                Runtime.getRuntime().availableProcessors() * 2,
                Runtime.getRuntime().availableProcessors() * 2,
                3,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(),
                new ThreadFactoryByPrefixName("io-tp-" + name),
                ObjectUtils233.getOrDefault(rejectedExecutionHandler, new ThreadPoolExecutor.AbortPolicy())
        );
    }

    public static ThreadPoolExecutor calculateThreadPool(String name, RejectedExecutionHandler rejectedExecutionHandler) {
        return new ThreadPoolExecutor(
                Runtime.getRuntime().availableProcessors(),
                Runtime.getRuntime().availableProcessors(),
                3,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(),
                new ThreadFactoryByPrefixName("calc-tp-" + name),
                ObjectUtils233.getOrDefault(rejectedExecutionHandler, new ThreadPoolExecutor.AbortPolicy())
        );
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy