The correct way to multithread inside Tomcat / Jetty

Here is my use case.

  • The client sends a request to the server.
  • The server needs to do the following 2.a Make a network call to get some data (D).
    2.b. Create a processor (P) to process the data.
  • P processes D and sends the response back to the client

Creating a processor is expensive (about 1-3 seconds). But this does not depend on the data D.

My plan is to make a network call and create a processor in parallel using two different threads.

I have never done multithreaded programming inside an application server. My question is the best way to handle threads inside the application server (in particular, Tomcat and Jetty).

Thank.

+3
source share
3

Executor. concurrency.

, .

, -, Tomcat, . , , , , , . , , (.. , , , ), , .

+5

Tomcat 7 Servlet 3.0 - API . : Tomcat 7

+4

If creating a processor (P) is expensive, can you pre-create a pool of P instances and reuse them the same way you create a database connection pool?

The Apache Commons Pool project can give you a starting point.

0
source

All Articles