• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Doubt in ThreadSafety

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

There was a question in whizlabs asked against threadsafety

if a servlet implements SingleThreadModel is it Thread Safe??

or only Instance Varaibles are threadsafe??
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you declare a servlet as being single threaded, then the instance fields of the servlet are thread safe. I am not sure but I think the servlet container can create multiple instances of the servlet to respond to the requests. So the static fields will not be thread safe any ways. I don't know what the servlet spec says about this...
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely, the container can create multiple instances, each servicing only one request. This makes the instance variables thread safe.
But the static variables are still thread unsafe.

Also, note that this multiple instance creation is not guaranteed by the spec. It is vendor dependent.
 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so
i would say even servlet Implements SingleThreadModel only instance varables are thread safe not the servlet is it??
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are other ways to introduce thread-unsafety into a web app besides servlet instance methods, e.g. sessions and context attributes. That's why that interface is deprecated - it doesn't guarantee thread-safety.
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic