options.maxReadBufferBytes = maxMessageSize;
options.stopTimeoutVal(5);
/*
* Create our own very special thread pool.
*/
final ThreadPoolExecutor pool = new SimpleThreadPool(numThreads, "ClientPool");
// periodically adjust the number of threads we need by checking how busy our threads are
SimpleTimer.getInstance().schedule(new Runnable() {
@Override
public void run() {
if (pool.getCorePoolSize() <= pool.getActiveCount()) {
int larger = pool.getCorePoolSize() + Math.min(pool.getQueue().size(), 2);
log.info("Increasing server thread pool size on " + serverName + " to " + larger);
pool.setMaximumPoolSize(larger);
pool.setCorePoolSize(larger);
} else {
if (pool.getCorePoolSize() > pool.getActiveCount() + 3) {
int smaller = Math.max(numThreads, pool.getCorePoolSize() - 1);
if (smaller != pool.getCorePoolSize()) {
// ACCUMULO-2997 there is a race condition here... the active count could be higher by the time
// we decrease the core pool size... so the active count could end up higher than
// the core pool size, in which case everything will be queued... the increase case
// should handle this and prevent deadlock
log.info("Decreasing server thread pool size on " + serverName + " to " + smaller);
pool.setCorePoolSize(smaller);
}
}
}
}
}, timeBetweenThreadChecks, timeBetweenThreadChecks);