*/ private class ThreadPool { List idle =

*/ private class ThreadPool { List idle = new LinkedList(); ThreadPool (int poolSize) { // Fill up the pool with worker threads for (int i = 0; i < poolSize; i++) { WorkerThread thread = new WorkerThread (this); // Set thread name for debugging. Start it. thread.setName ("Worker" + (i + 1)); thread.start(); idle.add (thread); } } /** * Find an idle worker thread, if any. Could return null. */ WorkerThread getWorker() { WorkerThread worker = null; synchronized (idle) { if (idle.size() > 0) { worker = (WorkerThread) idle.remove (0); } } return (worker); } /** * Called by the worker thread to return itself to the * idle pool. */ void returnWorker (WorkerThread worker) { synchronized (idle) { idle.add (worker); } } } /** * A worker thread class which can drain channels and echo-back * the input. Each instance is constructed with a reference to * the owning thread pool object. When started, the thread loops * forever waiting to be awakened to service the channel associated * with a SelectionKey object. * The worker is tasked by calling its serviceChannel() method * with a SelectionKey object. The serviceChannel() method stores * the key reference in the thread object then calls notify() * to wake it up. When the channel has been drained, the worker 155
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services

Comments are closed.