aspose file tools*
The moose likes Servlets and the fly likes Servlet requesting threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet requesting threads" Watch "Servlet requesting threads" New topic
Author

Servlet requesting threads

Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
Hi, I have a general question on how a servlet is invoked by multiple requests. Are these requests each a thread that all have access to the same <i>instance</i> of the servlet? If that's the case, can we consider a servlet also a implicit Runnable or Thread?
Thanks!
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The Servlet isn't a Runnable or a Thread, it's just a class used by one. You wouldn't consider String to be implicitly a Thread, just because you use one in a thread, would you?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
What is critical to note is that all instance variables of servlets are shared by all users of the servlets.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
Hi, my point is that all requests access the same instance of the servlet?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Not necessarily.
In most servlet containers they probably do use the same instance, (unless the serlvet is marked as SingleThreadMode), but the spec makes no guarantee about that, and allows container authors to use any strategy they feel is appropriate - single instance, multiple instance in the same JVM, multiple instances in different JVMs, multiple instances on separate machines and so on ...
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Exactly! A well designed server may, for example, create multiple instances of a servlet to handle server load.
Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
Thank you guys Frank and Thomas!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet requesting threads