File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Servlet Container related query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Container related query" Watch "Servlet Container related query" New topic
Author

Servlet Container related query

Harsh Motha
Greenhorn

Joined: Dec 19, 2008
Posts: 21
As we know that container after invoking the constructor of servlet it calls init method of the servlet in one thread and only once, the service methods are than called in different threads.

For our servlet to be used with the thread, our servlet or its above hierarchy should extend Thread class or implement runnable only than our servlets method can be used in threads. But for my surprise non of the class or interface up the hierarchy implement runnable or extend thread class.

I would appreciate if somebody can explain me.

Thanks and Regards
Harsh


SCJP 1.5 , SCWCD in Progress
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3827

Harsh Motha wrote:For our servlet to be used with the thread, our servlet or its above hierarchy should extend Thread class or implement runnable only than our servlets method can be used in threads.


Hint: Consider a simple class (which extends/implements nothing), and when you run that class in command prompt which thread runs it? If you can think of this you will get the answer to your question .


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 686


Hi Harsh,

First you know that servlet have no main method so, for run servlet or invoke servlet need a help.

So, no servlet class extends with thread class, servlet life cycle handle by container and container is another program which handle all thread complexity.

So, anything happens with servlet done by the container.

And in life cycle of servlet init() methid calls only one time after. And about your thread it is use for handle the user request.

when user hit request and if servlet already loaded into container then container create thread for process user request and call service() method according to call by post or get.

So, like that without extends thread calss container handle all complexity....





Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Harsh Motha
Greenhorn

Joined: Dec 19, 2008
Posts: 21
Hey Thanks Nishan and Vijitha , you made it clear.

Regards
Harsh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Container related query