• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need some info on servlets

 
felix thomas
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Felix,
Have you visited this Web site:

http://www.servlets.com

May be helpful.

Good Luck,
Avi.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
felix thomas
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic