Is it a wise decision to have multi threaded code in Servlets and JSP's as they themselves are internally multi threaded? Can anyone give me specific situations where you can go for this design decision? Thanks in Advance ------------------
you should consider using threads when you have clients accessing shared resources: HTTP servlets are typically capable of serving multiple clients concurrently. If the methods in your servlet do work for clients by accessing a shared resource, then you must either:
Synchronize access to that resource, or
Create a servlet that handles only one client request at a time
Hi Sreenivas U should avoid using threads in servlets and JSP. But in one scenario threads are useful. Suppose u have an Request which takes lot of time to process(for e.g an execution of procedure) then u can execute that procedure in a thread and return reponse to the request . This will prevent Browser Timeout to occur. After u finish executing procedure u can set an attribute in session and return the reponse u wanted to send. hope this is useful to u. Bye
As the previous poster has said, sometimes it can be very useful to have threads in a web application perform background tasks while the client session can proceed in parallel. The negative sides to this is obviously using server resources as having a large number of threads executing may slow the server significantly enough to affect new incoming requests. Using resources this way may make sense if you are servicing a paying customer but may not make sense if its guest users.