• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is servlet singlethreaded or multithreaded

 
shanthisri mocherla
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
Is a servlet single threaded or multithreaded.one thread runs at a time in service() method.Right???
can anyone please clarify this.

thanks

sri
 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi shanthisri,

By default, servlet is multithreaded unless you specify it through SingleThreadModel implemention or use isThreadSafe attribute for JSP (knowing that JSPs are turned into servlets).
 
kri shan
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess current version of Servlet spec, SingleThradModel is deprecated. I am not sure. Please check the spec.
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes .. SingleThreadModel is deprecated because there is nothing useful that we achieve from it.

If servlet A is implementing SingleThreadModel, then only one thread can be there for that servlet, at a time. But does this guarantee a thread safe application? What if Servlet B's thread modifies an attribute which servlet A is accessing.

Thats why this interface is useless and is deprecated too. It gives a wrong notion to programmers that implementing this interface guarantees thread-safeness. And HFSJ calls a person a poor servlet programmer if one uses SingleThreadModel.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic