final long deadline = now + unit.toMillis(timeout); if (deadline < 0L) { executeBlocking(task); return; startNewThread(task); threadCount = count + 1; return; startNewThread(task); threadCount = count + 1; return;
/** {@inheritDoc} */ public void setMaxThreads(final int maxThreads) { final Lock lock = this.lock; lock.lock(); try { final int oldLimit = this.maxThreads; if (maxThreads < coreThreads) { // don't let the max thread limit be less than the core thread limit. // the called method will signal as needed setCoreThreads(maxThreads); } else if (oldLimit < maxThreads) { // we're growing the number of extra threads // therefore signal anyone waiting to add tasks; there might be more threads to add removeCondition.signalAll(); } else if (oldLimit > maxThreads) { // we're shrinking the number of extra threads // therefore signal anyone waiting to remove tasks so the pool can shrink properly enqueueCondition.signalAll(); } else { // we aren't changing anything... return; } this.maxThreads = maxThreads; } finally { lock.unlock(); } }
/** {@inheritDoc} */ public void setKeepAliveTime(final long milliseconds) { setKeepAliveTime(milliseconds, TimeUnit.MILLISECONDS); }
startNewThread(task); threadCount = count + 1; return; startNewThread(task); threadCount = count + 1; return;
/** {@inheritDoc} */ public void setCoreThreads(final int coreThreads) { final Lock lock = this.lock; lock.lock(); try { final int oldLimit = this.coreThreads; if (maxThreads < coreThreads) { // don't let the max thread limit be less than the core thread limit. // the called method will signal as needed setMaxThreads(coreThreads); } else if (oldLimit < coreThreads) { // we're growing the number of core threads // therefore signal anyone waiting to add tasks; there might be more threads to add removeCondition.signalAll(); } else if (oldLimit > coreThreads) { // we're shrinking the number of core threads // therefore signal anyone waiting to remove tasks so the pool can shrink properly enqueueCondition.signalAll(); } else { // we aren't changing anything... return; } this.coreThreads = coreThreads; } finally { lock.unlock(); } }
@Override public void executeBlocking(Runnable task) throws RejectedExecutionException, InterruptedException { executor.executeBlocking(task); }
QueueExecutor exec = new QueueExecutor(); exec.execute();
public synchronized void start(final StartContext context) throws StartException { final TimeSpec keepAliveSpec = keepAlive; long keepAliveTime = keepAliveSpec == null ? Long.MAX_VALUE : keepAliveSpec.getUnit().toNanos(keepAliveSpec.getDuration()); QueueExecutor queueExecutor = new QueueExecutor(coreThreads, maxThreads, keepAliveTime, TimeUnit.NANOSECONDS, queueLength, threadFactoryValue.getValue(), blocking, handoffExecutorValue.getOptionalValue()); queueExecutor.setAllowCoreThreadTimeout(allowCoreTimeout); executor = new ManagedQueueExecutorService(queueExecutor); }
public static QueueExecutor createQueueExecutor(final int corePoolSize, final int maxPoolSize, final long keepAliveTime, final TimeUnit keepAliveTimeUnit, final Queue<Runnable> queue, final ThreadFactory threadFactory, final boolean blocking, final Executor handoffExecutor, final List<Object> taskFilterObjects) { return new QueueExecutor(corePoolSize, maxPoolSize, keepAliveTime, keepAliveTimeUnit, queue, threadFactory, blocking, handoffExecutor, createTaskFilter(taskFilterObjects)); }
startNewThread(task); threadCount = count + 1; return; startNewThread(task); threadCount = count + 1; return;
void setMaxThreads(int maxThreads) { executor.setMaxThreads(maxThreads); }
@Override public void executeBlocking(Runnable task, long timeout, TimeUnit unit) throws RejectedExecutionException, InterruptedException { executor.executeBlocking(task, timeout, unit); }
final long deadline = now + unit.toMillis(timeout); if (deadline < 0L) { executeBlocking(task); return; startNewThread(task); threadCount = count + 1; return; startNewThread(task); threadCount = count + 1; return;
startNewThread(task); threadCount = count + 1; return; startNewThread(task); threadCount = count + 1; return;
/** {@inheritDoc} */ public void setKeepAliveTime(final long milliseconds) { setKeepAliveTime(milliseconds, TimeUnit.MILLISECONDS); }
/** {@inheritDoc} */ public void setCoreThreads(final int coreThreads) { final Lock lock = this.lock; lock.lock(); try { final int oldLimit = this.coreThreads; if (maxThreads < coreThreads) { // don't let the max thread limit be less than the core thread limit. // the called method will signal as needed setMaxThreads(coreThreads); } else if (oldLimit < coreThreads) { // we're growing the number of core threads // therefore signal anyone waiting to add tasks; there might be more threads to add removeCondition.signalAll(); } else if (oldLimit > coreThreads) { // we're shrinking the number of core threads // therefore signal anyone waiting to remove tasks so the pool can shrink properly enqueueCondition.signalAll(); } else { // we aren't changing anything... return; } this.coreThreads = coreThreads; } finally { lock.unlock(); } }
void setCoreThreads(int coreThreads) { executor.setCoreThreads(coreThreads); }