Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

service() vs thread starting

 
Mamadou Touré
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

I'm a little bit confused.
Is the service() a mthod in each thread, or is it just in the servlet instance, and it wakes up a thread whenever there is a transaction ?

Reagrds
 
liao Yang
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The service() method is defined in a servlet class. There is only one instance of each servlet in each JVM. When there is a request to the servlet, the container get a thread from the thread pool or create a mew thread for this request and call the service() method of the requested servlet. So the service() method may run parallelly in more than threads.

Hope this helps.
 
Mamadou Touré
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it the servlet who runs the service() method or the container ?
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Container invokes service() for client request in a new thread.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!