users@jersey.java.net

[Jersey] Re: It's very hard to increase the number of worker threads in Jersey-Grizzly module.

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Thu, 31 May 2012 13:46:08 +0200

Oh, if server has been started - then we have to reconfigure the active
worker thread pool.

---------------------------------------------------
// create HTTP server
HttpServer server = GrizzlyServerFactory.createHttpServer(....);

// create the thread pool configuration
ThreadPoolConfig config = ThreadPoolConfig.newConfig().
                                          setPoolName("mypool").
                                          setCorePoolSize(10).
                                          setMaxPoolSize(300);

// reconfigure the thread pool
NetworkListener listener = httpServer.getListeners().iterator().next();
GrizzlyExecutorService threadPool = (GrizzlyExecutorService)
listener.getTransport().getWorkerThreadPool();
threadPool.reconfigure(config);


WBR,
Alexey.

On 05/31/2012 11:18 AM, mbuesch_at_gmail.com wrote:
> That doesn't work, after the Server is started:
>
> I checked with this example:
>
> int testPort = AvailablePortFinder.getNextAvailable(1024);
> HttpServer server =
> GrizzlyServerFactory.createHttpServer("http://localhost:" + testPort,
> new DefaultResourceConfig(Resource.class));
>
> // create the thread pool configuration
> ThreadPoolConfig config = createThreadConfig(poolName);
>
> // assign the thread pool
> NetworkListener listener =
> server.getListeners().iterator().next();
> log.info("NetworListener Name " + listener.getName());
> final TCPNIOTransport tcpnioTransport =
> listener.getTransport();
> tcpnioTransport.setWorkerThreadPoolConfig(config);
> final ThreadPoolConfig real =
> tcpnioTransport.getWorkerThreadPoolConfig();
> if (config.getCorePoolSize() != real.getCorePoolSize())
> log.info("CorePoolSize is not set. Should be :" +
> config.getCorePoolSize() + " but is :" + real.getCorePoolSize());
> if (config.getMaxPoolSize() != real.getMaxPoolSize())
> log.info("MaxPoolSize is not set. Should be :" +
> config.getMaxPoolSize() + " but is :" + real.getMaxPoolSize());