0

Previously I asked about threading on a servlet, which seems like a bad idea. So I'm thinking about importing MyJar.jar that creates a thread to do some processing.

The main process of MyJar.jar will be, accepting a file and do some validations on it.

But I want to know if it would be a problem for the servlet if the threading inside MyJar.jar will be a problem if there were multiple clients.

mj_nunez
  • 45
  • 1
  • 8
  • The problem is not where the thread is spawned but how it is spawned. I suggest you to look at this post http://stackoverflow.com/questions/533783/why-is-spawning-threads-in-java-ee-container-discouraged – Aris2World Sep 08 '16 at 07:56
  • It was suggested that using threads in a J(2)EE environment should be avoided. Normally the container takes care of threading issues. Some libraries would break this recommendation, even in the past. Nowdays however with Servlet 3 there is support for asynchronous processing (i.e. threads), and JEE7 containers also make container-managed threading facilities available to the developer. You may want to check out the [concurrency utilities for Java EE specification](https://jcp.org/ja/jsr/detail?id=236). – Nikos Paraskevopoulos Sep 08 '16 at 08:00
  • Here a good explanation about situations which require multithreading from a web app http://stackoverflow.com/questions/20491879/role-of-multithreading-in-web-application. To answer to your question: yes, it will be a problem because threads are a resource and resources are always limited. More thread per request take to less request per unit of time. A solution is to use thread pool to queue requests. But modern AS already manage this kind of issues. – Aris2World Sep 08 '16 at 08:08
  • @Aris2World thanks, maybe queuing request would do the trick . – mj_nunez Sep 08 '16 at 08:33
  • @NikosParaskevopoulos this is an interesting utility, I will try this out too, thanks for the reference – mj_nunez Sep 08 '16 at 08:37

0 Answers0