Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Starting servlets

 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've been reading on servlets and I'm still confused with the basics.

only 1 instance of servlet services multiple client requests. Is there a situation when it creates multiple instances?

Regards,
John Eipe
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a client makes a connection for a servlet, an instance of the servlet class is created and the new thread uses it to service the request.

Container does not create new instance of the servlet for each request, there can be multiple threads running the service method of the same servlet instance. and hence the class variables may create issues. Look at the servlet life cycle
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@sudhir nim
Is that your blog?

Thanks,
John Eipe
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe, on some web containers, multiple instances of Servlets implementing SingleThreadModel are created to handle the requests and they seem to reliably thread-safe.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, SingleThreadModel is deprecated.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
multiple instances of Servlets implementing SingleThreadModel are created to handle the requests and they seem to reliably thread-safe.

While that will lead to multiple instances being created, that by itself is not sufficient to guarantee thread-safety. Which, as Bear pointed out, is why it's deprecated and should not be used.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic