Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about isThreadSafe attribute of page directive  RSS feed

 
Jayavardhan geepi
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • 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
 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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 ..



 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • 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.)
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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?
 
vipul bondugula
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • 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.

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!