/** * {@inheritDoc} */ @Override public void execute(Runnable command) { execute(command,0,TimeUnit.MILLISECONDS); }
@Override public synchronized boolean offer(Runnable o) { //we can't do any checks if (parent==null){ return super.offer(o); } //we are maxed out on threads, simply queue the object if (parent.getPoolSize() == parent.getMaximumPoolSize()){ return super.offer(o); } //we have idle threads, just add it to the queue if (parent.getSubmittedCount()<(parent.getPoolSize())){ return super.offer(o); } //if we have less threads than maximum force creation of a new thread if (parent.getPoolSize()<parent.getMaximumPoolSize()){ return false; } //if we reached here, we need to add it to the queue return super.offer(o); }
public boolean force(Runnable o, long timeout, TimeUnit unit) throws InterruptedException { if ( parent==null || parent.isShutdown() ){ throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); } return super.offer(o,timeout,unit); //forces the item onto the queue, to be used if the task is rejected }
private ThreadPoolExecutor createUserThreadExecutor() { TaskQueue queue = new TaskQueue(SysProperties.THREAD_QUEUE_SIZE); int poolCoreSize = SysProperties.THREAD_POOL_SIZE_CORE; int poolMaxSize = SysProperties.THREAD_POOL_SIZE_MAX; poolMaxSize = poolMaxSize > poolCoreSize ? poolMaxSize : poolCoreSize; ExtendableThreadPoolExecutor userExecutor = new ExtendableThreadPoolExecutor(poolCoreSize, poolMaxSize, 5L, TimeUnit.MINUTES, queue, Threads.newThreadFactory("request-processor")); return userExecutor; }
private ExtendableThreadPoolExecutor createQueryExecutor() { TaskQueue queue = new TaskQueue(SysProperties.THREAD_QUEUE_SIZE); int poolCoreSize = SysProperties.THREAD_POOL_SIZE_CORE; int poolMaxSize = SysProperties.THREAD_POOL_SIZE_MAX; poolMaxSize = poolMaxSize > poolCoreSize ? poolMaxSize : poolCoreSize; ExtendableThreadPoolExecutor queryExecutor = new ExtendableThreadPoolExecutor(poolCoreSize, poolMaxSize, 2L, TimeUnit.MINUTES, queue, Threads.newThreadFactory("ddal-query-executor")); return queryExecutor; }
public boolean force(Runnable o) { if ( parent==null || parent.isShutdown() ){ throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); } return super.offer(o); //forces the item onto the queue, to be used if the task is rejected }