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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "need some info on servlets" Watch "need some info on servlets" New topic
Author

need some info on servlets

felix thomas
Ranch Hand

Joined: Jun 10, 2001
Posts: 89
hi,

I want to know the underlying functionality of how servlerts work in a application server or third party servlet engine.

1) How does the server call on the servlet residing on the server , what are the exact setps it takes.

2) How many instances of the servlet will be created on the server.
3) even if 100 clients request the servlet will there be ony one instance of servlet ?? how does the servlet handle so many request ???
4) Who calls the Init() method of the servlet ???





Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1134

Felix,
Have you visited this Web site:

http://www.servlets.com

May be helpful.

Good Luck,
Avi.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410


1) How does the server call on the servlet residing on the server , what are the exact setps it takes.
The container handles these details for you. Each container is free to do so how it sees fit as long as it complies with the Servlet Specs (see link below)

2) How many instances of the servlet will be created on the server.
One

3) even if 100 clients request the servlet will there be ony one instance of servlet ?? how does the servlet handle so many request ???
Yes, the servlet spawns a new thread for each request.

4) Who calls the Init() method of the servlet ???
The container.

The best place to find the answers to these types of questions is in the Servlet Specification itself. This is the document that the developers of a servlet container follow.
http://www.jcp.org/aboutJava/communityprocess/final/jsr154/

Also, Tomcat is the reference implementation for the servlet and JSP specs.
It's open source so you're free to download it and explore till your heart's content.
[ January 05, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
felix thomas
Ranch Hand

Joined: Jun 10, 2001
Posts: 89
hi, thanx for ur message but i have one question regarding mutipl e request handling

if one instance of servlet can handle mutiple requests usng threads

how are the variable safe guarded against threads. i mean public variables
have own specific value retaining in mutiple request for each user. How does that happen .
if one thread sets the value of int variable to 10, then if the the other request changes it to 20 , still how does the first request see it as 10

I hope u got the question
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I hope u got the question

I do get the question and it's a good one - an important one.

In order to be threadsafe, you need to avoid using instance variables except for values that apply to all threads, such initialization parameters.

Keep all thread specific variables local to your service methods (doPost, doGet, and service itself).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: need some info on servlets