Reputation: 510
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
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