wood burning stoves
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "threading in servlets??" Watch "threading in servlets??" New topic

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.
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:
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??
It's not a secret anymore!