public Thread newThread(Runnable r) { WorkerThreadImpl workerThread = new WorkerThreadImpl(threadPool, threadPool.name + "WorkerThread-" + threadPool.port + "-" + threadPool.workerThreadCounter.getAndIncrement(), r, threadPool.initialByteBufferSize); workerThread.setByteBufferType(threadPool.byteBufferType); workerThread.setPriority(threadPool.priority); return workerThread; } }
/** * must hold statelock while calling this method. * @param wt */ protected void startWorker(Worker wt) { final Thread thread = threadFactory.newThread(wt); thread.setName(getName() + "(" + nextThreadId() + ")"); thread.setUncaughtExceptionHandler(this); thread.setPriority(getPriority()); thread.setDaemon(true); if (thread instanceof WorkerThreadImpl) { final WorkerThreadImpl workerThread = (WorkerThreadImpl) thread; workerThread.setByteBufferType(getByteBufferType()); workerThread.setInitialByteBufferSize(getInitialByteBufferSize()); } wt.t = thread; workers.put(wt, System.currentTimeMillis()); wt.t.start(); }
/** * Create new {@link WorkerThreadImpl}. This method must be invoked * from a synchronized block. * @param increment - how many additional {@link WorkerThreadImpl} * objects to add * @param startThread - should newly added {@link WorkerThreadImpl} * objects be started after creation? */ protected void increaseWorkerThread(int increment, boolean startThread){ WorkerThreadImpl workerThread; int currentCount = threadCount; int increaseCount = threadCount + increment; for (int i=currentCount; i < increaseCount; i++){ workerThread = createWorkerThread( name + "WorkerThread-" + port + "-" + i, initialByteBufferSize); workerThread.setByteBufferType(byteBufferType); workerThread.setPriority(priority); if (startThread) workerThread.start(); workerThreads[i] = workerThread; threadCount++; } }