Adjusting the queue length

public ServerSocket(int port, int backlog) throws IOException

The operating system stores incoming connections for each port in a first-in, first-out queue until they can be accepted. The default queue length varies from operating system to operating system. However, it tends to be between 5 and 50. Once the queue fills up further connections are refused until space opens up in the queue. If you think you aren't going to be processing connections very quickly you may wish to expand the queue when you construct the server socket. For example,

 try {
    ServerSocket httpd = new ServerSocket(80, 50);
  }
  catch (IOException ex) {
    System.err.println(ex);
  }

Each system has a maximum queue length beyond which the queue cannot be expanded. If you ask for a queue longer than the maximum queue size on a particular platform, (generally around fifty to a hundred) then the queue is merely expanded to its maximum size.

Once the server socket has been constructed, you cannot change the queue length it uses.


Previous | Next | Top | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified April 18, 1997