jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Threads in servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Threads in servlets" Watch "Threads in servlets" New topic
Author

Threads in servlets

dluckose
Greenhorn

Joined: Jul 31, 2001
Posts: 6
Can threads be used in servlets?
Please give me a answer
Kalpesh Soni
Ranch Hand

Joined: Jan 02, 2001
Posts: 312
yes i think so


Test 094, IBM WID 6.0 cert
SCJP 1.2
SCBCD 1.3 Beta
SCWCD 1.4 Beta
SCMAD Beta
SCDJWS Beta

KS
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17145
    
  27

Yes, but since a servlet is an in-and-out type of environment (rather than running the way an executable program does), the thread would either have to run quickly enough to make the need for a thread questionable or the thread would have to be stored in a non-volatile part of the class.
For a long-running process, it's often better to run the process as a separate server task and have the servlet queue requests / get responses from there (JMS is a good way to do this). That way you don't bog down the servlet mechanism.


An IDE is no substitute for an Intelligent Developer.
Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
dluckose, your user name does not comply to the naming standards you agreed to when you registered here http://www.javaranch.com/name.jsp . please register again with a valid user name consisting of a first name, and a last name. Thank you.


Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads in servlets
 
It's not a secret anymore!