Is it not encouraged to use threads in web application? Is it not encouraged to use threads in web application? multithreading multithreading

Is it not encouraged to use threads in web application?


Using threads in a webapp is not a problem per se. It just depends why and how you use them. In particular, if you have 1000 users, and you start one thread for each of these users, you'll bring the JVM to its knees.

But if threads are launched very raraely, for a specific, reduced set of users and use-cases, and if you use a thread pool to limit the number of such threads, you shouldn't have any problem. It's just important to understand what you're doing.

Also, make sure to not pass a HttpServletRequest or HttpServletResponse object to such a thread, because they aren't meant to be used by several concurrent threads, and they are not supposed to be used anymore once the request has been handled.