synchronized void cleanIdel() { for (WorkerThread workerThread : workerThreads) { if (workerThread.isIdle()) { workerThreads.remove(workerThread); workerThread.terminate(); } } }
private WorkerThread createWorkerThread() { WorkerThread wThread = new WorkerThread(); wThread.start(); workerThreads.add(wThread); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } return wThread; }
synchronized void service(Request request) { boolean idleNotFound = true; for (WorkerThread workerThread : workerThreads) { if (workerThread.isIdle()) { workerThread.setReq(request); idleNotFound = false; break; } } if (idleNotFound) { WorkerThread workerThread = createWorkerThread(); workerThread.setReq(request); } }