Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Configuring a separate threadpool for async execution

Thank you very much, Simone.

My confusion was about if we have to tell Jetty about the thread pool where the async requests are run and my understanding is that we have to. If that is correct, how do we tell Jetty about the thread pool to which it would then submit the task for execution?


On Sun, Jul 21, 2019 at 8:58 PM Simone Bordet <sbordet@xxxxxxxxxxx> wrote:

On Wed, Jul 10, 2019 at 12:57 PM Abhirama <abhirama@xxxxxxxxx> 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 ( 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
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
Developer advice, training, services and support
from the Jetty & CometD experts.
jetty-users mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top