• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about isThreadSafe attribute of page directive

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
isThreadSafe says whether the generated servlet should implement SingleThreadModel(STM) or not.
I read in headfirst that , the default value of this attribute is true which means app is threadsafe.
So, doesn't this imply that all servlets are threadsafe?(generated or written by us).
Is it true?

And, false value of the attri means, we are indicating the desire of STM implementation.

Please clarify the issues i have..

Thanks
 
Ranch Hand
Posts: 129
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And, false value of the attri means



Please use real words when posting to the forums. Try to avoid Abbreviations such as "attri" in place of "attribute" ...

Please click this link ⇒UseRealWords for more information.

If you are setting isThreadSafe property to false you will have many instances(say N numbers) of the servlet will be generated, loaded and initialized, with the service method of each(say N numbers) instance synchronized properly .If you are setting isThreadSafe property to true a single instance of the servlet will be generated , loaded and initialized in the container as normally ....and true is the default value ..



 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I read in headfirst that , the default value of this attribute is true which means app is threadsafe.
So, doesn't this imply that all servlets are threadsafe?(generated or written by us).


I think you're misinterpreting what that attribute means. Setting it to true does not make the JSP thread-safe - rather it is an assertion by the developer that it is thread-safe. The default value is true because there is no reason to write a JSP that is not thread-safe, but it also means that the burden is on the developer to ensure that that is the case. (It is perfectly possible to set the attribute to true for a JSP that is not actually thread-safe - this will result in nasty consequences.)
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vijin das wrote:If you are setting isThreadSafe property to false you will have many instances(say N numbers) of the servlet will be generated, loaded and initialized, with the service method of each(say N numbers) instance synchronized properly .If you are setting isThreadSafe property to true a single instance of the servlet will be generated , loaded and initialized in the container as normally ....and true is the default value ..


I'm curious how you arrived at these conclusions--do you have a link you used for reference?
 
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Download SCWCD pdf document and check isThreadSafe attribute.

If isThreadSafe attribute is true , then multiple requests are handled by threads of single servlet instance.Each thread handles a request.

the default value of this attribute is true which means application is threadsafe.
So, doesn't this imply that all servlets are threadsafe?



These two lines are misinterpreted here.First line asserts jsp's are thread-safe.
second line depends on your coding in jsp page. If you use scriptlet, declarative type of code in jsp's then threading issues may arise.
Check the below example for your reference.


I am not sure whether declaration of count will work fine or not..
According to me count is having class level scope.This means every thread will have count value to 0 first time..
If count value is declared in init(), then the above code works fine..

Thanks & Regards,
Vipul Kumar.

 
rubbery bacon. rubbery tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic