Reputation: 12582
final SslSocketConnector conn = new SslSocketConnector(sslContextFactory);
conn.setReuseAddress(true);
conn.setPort(port);
ResourceHandler resources = new ResourceHandler();
resources.setCacheControl("no-cache");
resources.setDirectoriesListed(true);
resources.setWelcomeFiles(new String[] { "abc.blank" });
resources.setResourceBase(fileLoc);
server.setConnectors(new Connector[] { conn });
server.setHandler(resources);
I have a Jetty (8.0) setup as above. But since my file is large, i need to define max number of connections allowed. What should I set?
Upvotes: 0
Views: 2349
Reputation: 12582
This is what worked for me, after considering the solution suggested by @wolfrevo
QueuedThreadPool tp = new QueuedThreadPool(1);
// This will keep requests in queue until the current job is over
// or client times out.
tp.setMaxQueued(connectionCount);
tp.setMaxThreads(threadCount);
tp.setMaxIdleTimeMs(maxIdle);
server.setThreadPool(tp);
Upvotes: 0
Reputation: 7182
I would recommend using the Quality of Service filter to limit it to a specific number as opposed to trying to use the thread pool in this way. This way to can lock down a specific location in your app, or a particular servlet path to this without affecting the entire webapp.
http://www.eclipse.org/jetty/documentation/current/qos-filter.html
[edit] And I would recommending using the DefaultServlet to serve the static content here, it is typically better since it supports caching and ranges (resource handler has been improved with some of this in Jetty 9 though).
Upvotes: 0
Reputation: 7303
Try the following:
QueuedThreadPool tp = (QueuedThreadPool) server.getThreadPool();
tp.setMaxThreads(10);
server.setThreadPool(tp);
Upvotes: 1