13

I'm using jetty 9.1.0, embedded, and would like to set both port and ThreadPool. I see a constructor for each, but don't see how to use one of those, and then any way to set the other.

doing this

Server server = new Server(9090);

or

Server server = new Server(new QueuedThreadPool(100, 10));

but there's no setPort or setThreadPool on Server.

Alper Akture
  • 2,445
  • 1
  • 30
  • 44

4 Answers4

10
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(500);

Server server = new Server(threadPool);

ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
http.setPort(81);

server.addConnector(http);
vinga
  • 1,912
  • 20
  • 33
4

I can't test it right know, but I assume you can

a) Use a configuration file and load it

or

b) Use the QueuedThreadPool and do the following:

 SelectChannelConnector connector = new SelectChannelConnector();
 connector.setPort(9090);
 server.addConnector(connector);
nils
  • 1,362
  • 1
  • 8
  • 15
  • 1
    Looks like in the version I have, it's ServerConnector, I don't see a SelectChannelConnector, but using ServerConnector may work, I'll give you credit once I try it out. Thanks! – Alper Akture Apr 27 '14 at 22:09
  • 3
    For jetty 9, it's a bit different. I found a good example [here](http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java) – Alper Akture Apr 29 '14 at 02:03
3
    Server server = new Server(new QueuedThreadPool(128, 8));
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());

    connector.setPort(8897);
    server.addConnector(connector);
Jose Alban
  • 7,286
  • 2
  • 34
  • 19
0

You could go with XML configuration from /etc/jetty.xml file, which is well documented and also use beans with Spring configuration.

There's no constructor that will take ThreadPool and port together.

Ostati
  • 4,623
  • 3
  • 44
  • 48