FileDocCategorySizeDatePackage
CalcServer.javaAPI DocExample2375Sat Jul 31 20:24:04 BST 2004javathreads.examples.ch12.example4

CalcServer

public class CalcServer extends TCPNIOServer

Fields Summary
static ThreadPoolExecutor
pool
Constructors Summary
Methods Summary
protected voidhandleClient(java.nio.channels.SelectionKey key)

        SocketChannel sc = (SocketChannel) key.channel();
        ByteBuffer buffer = ByteBuffer.allocateDirect(8);
        sc.read(buffer);
        buffer.flip();
        long n = buffer.getLong();
        FibClass fc = new FibClass(n, sc);
        pool.execute(fc);
    
public static voidmain(java.lang.String[] args)

        CalcServer cs = new CalcServer();
        cs.port = Integer.parseInt(args[0]);
        int tpSize = Integer.parseInt(args[1]);
        pool = new ThreadPoolExecutor(
                        tpSize, tpSize, 50000L, TimeUnit.MILLISECONDS,
                        new LinkedBlockingQueue<Runnable>());
        cs.run();
        System.out.println("Calc server waiting for requests...");
    
protected voidregisteredClient(java.nio.channels.SocketChannel sc)