SelectSocketsThreadPoolpublic class SelectSocketsThreadPool extends SelectSockets Specialization of the SelectSockets class which uses a thread pool
to service channels. The thread pool is an ad-hoc implementation
quicky lashed togther in a few hours for demonstration purposes.
It's definitely not production quality.
Created May 2002 |
Fields Summary |
---|
private static final int | MAX_THREADS | private ThreadPool | pool |
Methods Summary |
---|
public static void | main(java.lang.String[] argv)
// -------------------------------------------------------------
new SelectSocketsThreadPool().go (argv);
| protected void | readDataFromSocket(java.nio.channels.SelectionKey key)Sample data handler method for a channel with data ready to read.
This method is invoked from the go() method in the parent class.
This handler delegates to a worker thread in a thread pool to
service the channel, then returns immediately.
WorkerThread worker = pool.getWorker();
if (worker == null) {
// No threads available, do nothing, the selection
// loop will keep calling this method until a
// thread becomes available. This design could
// be improved.
return;
}
// invoking this wakes up the worker thread then returns
worker.serviceChannel (key);
|
|