Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top