1

Sometimes (pretty rarely) when I connect to a running instance of a com.sun.net.httpserver.HttpServer I get a "connection refused" message back.

Anybody know why this might be? Is there a thread limit to the number of connections it can handle? Can I increase it? Thanks. -r

skaffman
  • 398,947
  • 96
  • 818
  • 769
rogerdpack
  • 62,887
  • 36
  • 269
  • 388

1 Answers1

2

From the doc:

When binding to an address and port number, the application can also specify an integer backlog parameter. This represents the maximum number of incoming TCP connections which the system will queue internally. Connections are queued while they are waiting to be accepted by the HttpServer. When the limit is reached, further connections may be rejected (or possibly ignored) by the underlying TCP implementation. Setting the right backlog value is a compromise between efficient resource usage in the TCP layer (not setting it too high) and allowing adequate throughput of incoming requests (not setting it too low).

You may be seeing this.

Alternatively, have you set an executor using setExecutor(). The default executor may have fewer threads configured than you need, and a suitably-configured ThreadPoolExecutor may work.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • setExecutor--thank you very much--wonder what the default configuration is... [the java docs, as usual, with " a default implementation is used"] – rogerdpack Oct 29 '09 at 18:46
  • I just experienced different default behavior on two versions of OpenJDK (Ubuntu 12.04 and ArchLinux -- "1.7.0_21" vs "1.7.0_15"): on Ubuntu it worked as expected but on ArchLinux the default is apparently single-threaded?? Setting the Executor to use a thread pool solved the problem. – Joseph May 20 '13 at 05:34