aspose file tools*
The moose likes Servlets and the fly likes threading in servlets?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "threading in servlets??" Watch "threading in servlets??" New topic
Author

threading in servlets??

saahil sinha
Ranch Hand

Joined: Apr 07, 2003
Posts: 68
Hi ,
I would like to know how and when to implement threading in servlets.If one could please explain to give a link ill be highly grateful.
Thanx
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Servlets run in a multi-threaded environment. You don't need to "implement" threading in a servlet. UNLESS of course, you are talking about using a class that extends Thread or implements Runnable within your servlet. In which case you proceed "as usual" just like in any other program where you want to use threads. The caveat is: Some enterprise-level containers do not allow you to create your own threads. Tomcat lets you, iPlanet App Server doesn't.

If you're talking about "are servlets mutlithreaded" and "what are the issues surrounding that?", then just search this forum for the words "multithreaded or threading".

Here's a few to get you started:
http://www.coderanch.com/t/355806/Servlets/java/Thread-safety
http://www.coderanch.com/t/355472/Servlets/java/static-methods-not-thread-safe
Wendal Park
Ranch Hand

Joined: Aug 28, 2001
Posts: 39
Just a friendly note that one should treat all servlets as multithreaded, and that regardless whether you have explicit new Threads in your methods, all your variables should be declared as local as possible. The best practice is to keep their scope within methods (even database connections).


MSc, BSc, SCJP 1.4<br /> <img src="graemlins/banghead.gif" border="0" alt="[banghead]" /> SCBCD
saahil sinha
Ranch Hand

Joined: Apr 07, 2003
Posts: 68
thanx guys tht was a big load of my head was a bit confused on tht issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: threading in servlets??
 
Similar Threads
MULTI-THREADING
thread creation in struts
basic question...
Lets play a word game...
Making current thread sleep in JS for progress bar