This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Threads in JSP's and servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Threads in JSP Watch "Threads in JSP New topic
Author

Threads in JSP's and servlets

Sreenivas Makala
Greenhorn

Joined: Jun 14, 2001
Posts: 4
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
------------------
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
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

you may read some more at: http://www.java.sun.com/docs/books/tutorial/servlets/client-interaction/index.html
sandeep Gajbhiye
Greenhorn

Joined: Jul 13, 2001
Posts: 3
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
John Aiken
Greenhorn

Joined: Jul 17, 2001
Posts: 3
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.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Your "thejavagod" name does not comply with the JavaRanch naming policy. Please spare a moment and re-register with a name that meets the requirements.
Thanks!


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Sreenivas Makala
Greenhorn

Joined: Jun 14, 2001
Posts: 4
I thank you all for your valuable inputs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads in JSP's and servlets
 
Similar Threads
Is Servlets by default a single threaded model or multi threaded model
servlet container and multi threading
why servlets are multi - threaded
Threads in Servlets
is struts thread safe