private synchronized void checkWorkforce() { if (mWorkThreads.isEmpty() || (mPendingJobs.size() / mWorkThreads.size() > mGrowthTriggerRation)) { verbose("Request to incrementing workforce from %1$d", mWorkThreads.size()); if (mWorkThreads.size() >= MAX_WORKFORCE_SIZE) { verbose("Already at max workforce %1$d, denied.", MAX_WORKFORCE_SIZE); return; } for (int i = 0; i < mMWorkforceIncrement; i++) { Thread t = new Thread(this, mName + "_" + mThreadId.incrementAndGet()); t.setDaemon(true); mWorkThreads.add(t); t.start(); } verbose("thread-pool size=%1$d", mWorkThreads.size()); } }
private synchronized void checkWorkforce() { if (mWorkThreads.isEmpty() || ((mPendingJobs.size() / mWorkThreads.size() > mGrowthTriggerRatio) && mGrowthTriggerRatio > 0)) { verbose("Request to incrementing workforce from %1$d", mWorkThreads.size()); if (mWorkThreads.size() >= MAX_WORKFORCE_SIZE) { verbose("Already at max workforce %1$d, denied.", MAX_WORKFORCE_SIZE); return; } for (int i = 0; i < mMWorkforceIncrement; i++) { Thread t = new Thread(this, mName + "_" + mThreadId.incrementAndGet()); t.setDaemon(true); mWorkThreads.add(t); t.start(); } verbose("thread-pool size=%1$d", mWorkThreads.size()); } }
private synchronized void reduceWorkforce() throws InterruptedException { verbose("Decrementing workforce from " + mWorkThreads.size()); // push a the right number of kiss of death tasks to shutdown threads. for (int i = 0; i < mMWorkforceIncrement; i++) { _push(new QueueTask<>(QueueTask.ActionType.Death, null)); } }
private synchronized void reduceWorkforce() throws InterruptedException { verbose("Decrementing workforce from " + mWorkThreads.size()); // push a the right number of kiss of death tasks to shutdown threads. for (int i = 0; i < mMWorkforceIncrement; i++) { _push(new QueueTask<T>(QueueTask.ActionType.Death, null)); } }
verbose("Creating a new working thread %1$s", threadName); mQueueThreadContext.creation(Thread.currentThread()); } catch (IOException e) { final QueueTask<T> queueTask = mPendingJobs.take(); if (queueTask.actionType== QueueTask.ActionType.Death) { verbose("Thread(%1$s): Death requested", threadName); return; verbose("Thread(%1$s): scheduling %2$s", threadName, job.getJobTitle()); verbose("Thread(%1$s): job %2$s finished", threadName, job.getJobTitle()); verbose("Thread(%1$s): queue size %2$d", threadName, mPendingJobs.size()); } finally { try { verbose("Thread(%1$s): destruction", threadName); mQueueThreadContext.destruction(Thread.currentThread()); } catch (IOException e) {
verbose("Creating a new working thread %1$s", threadName); mQueueThreadContext.creation(Thread.currentThread()); } catch (IOException e) { final QueueTask<T> queueTask = mPendingJobs.take(); if (queueTask.actionType== QueueTask.ActionType.Death) { verbose("Thread(%1$s): Death requested", threadName); return; verbose("Thread(%1$s): scheduling %2$s", threadName, job.getJobTitle()); verbose("Thread(%1$s): job %2$s finished, result=%3$b", threadName, job.getJobTitle(), result); verbose("Thread(%1$s): queue size %2$d", threadName, mPendingJobs.size()); } finally { try { verbose("Thread(%1$s): destruction", threadName); mQueueThreadContext.destruction(Thread.currentThread()); } catch (IOException | InterruptedException e) {