Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Container related query

 
Harsh Motha
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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....



 
Harsh Motha
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Thanks Nishan and Vijitha , you made it clear.

Regards
Harsh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic