user3364652
user3364652

Reputation: 510

How to run something on servlet that will continue to run after the servlet sends the response?

I am sending a jQuery ajax request to a servlet. I want the servlet to handle the request and response. But just before the servlet returns the response, I want it to start to run something that will continue to run after the response is returned.

Is using a new thread the best way to do it? Or something else?

Upvotes: 0

Views: 274

Answers (1)

Benjamin
Benjamin

Reputation: 1846

You may use plain threads which is not the best idea. You can also use some of the thread pools provided by the standard API (see the java.util.concurrent.Executors class).

If you are in a Java EE environment, then it's better to use @Asynchronous EJBs or javax.enterprise.concurrent.ManagedExecutorService.

Upvotes: 1

Related Questions