• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need some info on servlets

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ???





 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Felix,
Have you visited this Web site:

http://www.servlets.com

May be helpful.

Good Luck,
Avi.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
reply
    Bookmark Topic Watch Topic
  • New Topic