*/ private class ThreadPool { List idle =
* thread returns itself to its parent pool. */ private class WorkerThread extends Thread { private ByteBuffer buffer = ByteBuffer.allocate (1024); private ThreadPool pool; private SelectionKey key; WorkerThread (ThreadPool pool) { this.pool = pool; } // Loop forever waiting for work to do public synchronized void run() { System.out.println (this.getName() + ” is ready”); while (true) { try { // Sleep and release object lock this.wait(); } catch (InterruptedException e) { e.printStackTrace(); // Clear interrupt status this.interrupted(); } if (key == null) { continue; // just in case } System.out.println (this.getName() + ” has been awakened”); try { drainChannel (key); } catch (Exception e) { System.out.println (”Caught ‘” + e + “‘ closing channel”); // Close channel and nudge selector try { key.channel().close(); } catch (IOException ex) { ex.printStackTrace(); } key.selector().wakeup(); } key = null; // Done. Ready for more. Return to pool this.pool.returnWorker (this); } } 156
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services