FileDocCategorySizeDatePackage
TCPThrottledServer.javaAPI DocExample960Sun Dec 07 10:45:00 GMT 2003javathreads.examples.ch12

TCPThrottledServer

public abstract class TCPThrottledServer extends Object implements Runnable

Fields Summary
ServerSocket
server
Thread[]
serverThreads
volatile boolean
done
Constructors Summary
Methods Summary
public voidrun()

        while (!done) {
            try {
                Socket data;
                data = server.accept();
                run(data);
            } catch (IOException ioe) {
                System.out.println("Accept error " + ioe);
            }
        }
    
public voidrun(java.net.Socket data)

    
public synchronized voidsetDone()

        done = true;
    
public synchronized voidstartServer(int port, int nThreads)


             
        server = new ServerSocket(port);

        serverThreads = new Thread[nThreads];
        for (int i = 0; i < nThreads; i++) {
            serverThreads[i] = new Thread(this);
            serverThreads[i].start();
        }