Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes service() vs thread starting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "service() vs thread starting" Watch "service() vs thread starting" New topic

service() vs thread starting

Mamadou Touré
Ranch Hand

Joined: Dec 27, 2007
Posts: 189
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 ?


SCJP 5 (76%)
SCWCD 5 (86%)
SCBCD 5(70%)
"The greatest glory in living lies not in never falling, but in raising every time we fall.".. Nelson Mandela
liao Yang
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
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

Joined: Dec 27, 2007
Posts: 189
Is it the servlet who runs the service() method or the container ?
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Container invokes service() for client request in a new thread.

I agree. Here's the link:
subject: service() vs thread starting
It's not a secret anymore!