Hi, On Wed, Jul 10, 2019 at 12:57 PM Abhirama <[email protected]> wrote: > > Hi, > > I'm using embedded Jetty in my application and have a few servlets which I > want configuIred to process requests asynchronously. I'm using the simplest > way of doing this (https://docs.oracle.com/javaee/7/tutorial/servlets012.htm) > and I do see that the execution of the servlet prior to > httpServletRequest.startAsync() is processed in thread 'A' and the async > processing happens as part of thread 'B' > > However, I notice that threads A and B seem to be coming from the same thread > pool (the thread names share the same prefix). From whatever I could find, > Jetty, by default, uses only one QueuedThreadPool to process requests and I > believe threads A and B are coming from this very threadpool. >
That is correct if you use AsyncContext.start(Runnable). > My question is - how is async processing helping in this case where you are > taking away another thread from the same thread pool? Is my understanding > correct? Is my configuration missing something? Is there a way to configure a > thread pool to be used exclusively for async execution so that the container > threads accepting HTTP requests can continue to accept requests? > If you want to use a thread pool to run your tasks, you have to set it up yourself. If you use AsyncContext.start(Runnable) then Jetty will use the default thread pool. With AsyncContext.start(Runnable), if your tasks block for a long time, you may exhaust the Jetty thread pool, which will make the server not able to process further requests until some thread is freed. OTOH, if you use your own thread pool to run your tasks, you have more control on how many you can run concurrently and when additional ones are queued, and the server is free to process further requests - although you may end up queueing a lot of tasks and possibly exhaust the heap memory. You have to decide what's best for your case. -- Simone Bordet ---- http://cometd.org http://webtide.com Developer advice, training, services and support from the Jetty & CometD experts. _______________________________________________ jetty-users mailing list [email protected] To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users
