• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Clear my doubts please ...

 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have this small doubt about Servlets :

When it's said that there's a seperate thread for each request, is that seperate thread the doGet or doPost method ???

Please clear my doubt and advice me ...

Best regards ...
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
when the web application is loaded, container creates instance of servlet,just one instance of servlet created, whenever a new request comes container creates a new thread and same objeat is passed to the new thread
eg Myservlet ser=new Myservlet();(suppose this is the object created by container )
Thread t1=new Thread(ser);-----for one client

Thread t2=new Thread(ser);-----for another client
passing same object means both thread will do the same job but for differnt clients as and when they get request from the client
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice nice

But what about the doGet and doPost ?
Are they seperate threads ?

Thanks alot ...
 
sweety singh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
when first thread t1 is in execution it will call ser(servlet) doGet()or doPost()
and when thread t2 is executing it will again call ser doGet() or doPost()
there is nothing like methods are running in threads
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I meant, does it (doGet or doPost) run in a seperate thread (thread of execution) ?

There's this thing that I'm not getting : the container creates the thread, and then it calls the services method passing it the request and response objects, BUT, what is the purpose the thread ???

It's really annoying me

What does that thread do ?

And the service method itself calls the doGet or doPost ...

Please i need a clear explaination ...

Thanks in advance ...
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, doGet/ doPost run in seperate thread.

service/doGet/doPost, being instance methods need to be called on the Servlet instance. But the container doesn't create seperate instances for each request(rather request thread).Instead it uses the same instance to invoke service(and hence, doGet/doPost).
Executing each request in seperate thread enables container to handle multiple request simultaneously without creating numerous servlet instances which may take all container resources.

I am not sure of how container manages request threads but here is what happens w.r.t doGet/doPost.

First Request:
Container receives request, creates an instance of this servlet, calls service() on this instance, service() delegates to doGet/doPost.

subsequent Requests:
Container receives request, uses the instance already created(No new instance is created), calls service(), service() delegates to doGet/doPost.

Hope this helps...

Thanks and regards,
Saurabh
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mr.Saurabh ...

Best regards ...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic