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

abs.api.OrderedThreadPoolExecutor Maven / Gradle / Ivy

package abs.api;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * TODO An internal API to be documented
 *
 * @author Behrooz Nobakht
 * @since 1.0
 */
public class OrderedThreadPoolExecutor extends ThreadPoolExecutor {

	private static final int NCPU = Runtime.getRuntime().availableProcessors();

	/**
	 * 

* Constructor for OrderedThreadPoolExecutor. *

* * @param queue * a {@link java.util.concurrent.BlockingQueue} object. */ public OrderedThreadPoolExecutor(final BlockingQueue queue) { super(1, NCPU, 1, TimeUnit.MINUTES, queue, new RejectedExecutionHandler() { @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { // ignore } }); } /** {@inheritDoc} */ @Override protected RunnableFuture newTaskFor(Callable callable) { if (callable instanceof ComparableRunnableFuture == false) { throw new IllegalArgumentException("Task is not an instance of " + ComparableRunnableFuture.class + " : " + callable); } return (RunnableFuture) callable; } /** {@inheritDoc} */ @Override protected RunnableFuture newTaskFor(Runnable runnable, T value) { if (runnable instanceof ComparableRunnableFuture == false) { throw new IllegalArgumentException("Task is not an instance of " + ComparableRunnableFuture.class + " : " + runnable); } return (RunnableFuture) runnable; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy