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

devutility.internal.util.concurrent.ExecutorServiceUtils Maven / Gradle / Ivy

There is a newer version: 1.3.8.1
Show newest version
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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy