This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets" Watch "Servlets" New topic
Author

Servlets

Rajeev Iyer
Ranch Hand

Joined: Jun 19, 2002
Posts: 42
Hi...
Is it necessary to have threads in servlets, because as it is, the service method run on multiple threads to cater to multiple client requests.
If needed, how can we use threads in servlets?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Hi,
U need not worry abt managin threads. The Web container does the job for U.
The only thing that u need to know is that ur servlet is muti-threaded.
If u want to make it single threaded make it implement SingleThreadModel (Ensures that one request is processed at a time)


Groovy
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
You should only use a Thread to carry out processes that are separate from the request - response cycle. For example, I have used Threads to manage a cache of data files, send email, and download XML formatted headlines. In every case these Threads are attached to separate utility objects, NOT servlet code.
Bill


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets
 
Similar Threads
multiple instances
Remote calling mechanism question
why cant there be multiple servlets running at the same time?
Variables in Portlets
Better way of random number generation using multiple threads