Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set both port and thread pool using embedded jetty, v 9.1.0

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.

like image 695
Alper Akture Avatar asked Apr 27 '14 21:04

Alper Akture


People also ask

How many connections can Jetty handle?

In HTTP/1.1, a destination holds a pool of connections (controlled by maxConnectionsPerDestination, by default 64). So if you send requests in a tight loop, assuming connection establishment takes zero time, you can have at most 64 (on the network) + 1024 (queued) outstanding requests. The next one will be rejected.

How do you set a Jetty home window?

JETTY_HOME implies the path where jetty is installed and defined as JETTY_HOME on your environment variables. Too see the varible (path of the directory); based on your OS run echo %JETTY_HOME% for Windows; or echo $JETTY_HOME for Unix on your command line / terminal.

What are Jetty threads?

Jetty has a single ThreadPool, for all operations. A Thread is a Thread is a Thread. There is no distinction between selector / acceptor / requests / async processing / async read / async write / websocket / proxy / client / etc. At last count, in Jetty 9.4.


2 Answers

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);
like image 68
vinga Avatar answered Nov 01 '22 11:11

vinga


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);
like image 33
nils Avatar answered Nov 01 '22 09:11

nils