devutility.internal.util.concurrent.ExecutorServiceUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of devutility.internal Show documentation
Show all versions of devutility.internal Show documentation
Some utilities for Java development
package devutility.internal.util.concurrent;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import devutility.internal.base.SystemUtils;
public class ExecutorServiceUtils {
/**
* ExecutorServiceHolder
*/
private static class ExecutorServiceHolder {
/**
* Processors count for the current machine
*/
private static int processorsCount = SystemUtils.processorsCount();
/**
* Default ThreadPoolExecutor object
*/
public static ExecutorService executorService = new ThreadPoolExecutor(processorsCount, processorsCount * 5, 3, TimeUnit.SECONDS, new LinkedBlockingQueue(), (thread) -> {
return new Thread(thread);
});
}
/**
* Get default ThreadPoolExecutor
* @return ExecutorService
*/
public static ExecutorService threadPoolExecutor() {
return ExecutorServiceHolder.executorService;
}
}