Reputation: 33083
How can I make an embedded Jetty instance single-threaded?
I have tried
server.setThreadPool(new QueuedThreadPool(1))
but it complains that there are not enough threads in the pool, and hangs. This still happens even if I use a SocketConnector
instead of a NIO connector.
(The reason I want this is I'm trying to solve this problem - which I currently have a bounty on, by the way! - and Google's LocalServiceTestHelper
only seems to take effect in the current thread.)
Upvotes: 2
Views: 1501
Reputation: 33083
The SocketConnector
needs 2 threads - one to wait for connections, and one to service a connection. Other connectors may need even more, so use a SocketConnector
.
Also, you must ensure that each connection is closed on the client end before you make another connection - otherwise the server will keep it open for a while, in case any more HTTP requests are to be sent. Make sure you disable Keep-Alive.
Upvotes: 2