Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final Mock Exam question 19

 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Final Mock Exam question 19
I will not type the entire question but will ask the doubt instead
Q:Given a classic tag. As we know that Classic tags are re-used which mean they are not instantiated again. Now if two threads invoke the classic tag
Will two new instances be created ? as a result the member variables are thread safe?

What is the case with simple tags?
 
Rufus Addis
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding is that there will always be a seperate occurance of the Classic Tag handler per thread.

So for example if two threads invoke the classic tag, then there will be two instances of the classic tag handler available, and the member variables will affectively be thread safe.

However these instances of the classic tag handler may be either be new created instances, or re-use existing instances (that are no longer being used). Obviously re-used tags handlers will have member variables in an indetermant state.

Simple tags always get new instances!

Rufus.
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

SimpleTags are not reused so for every request it will instantiate the class
so it is thread safe.There is no concurrency problem here with respect to instance variables, however the static variables will be shared between the request and it will be not thread safe.

Thanks
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lot of bugs with HFSJ
 
Rufus Addis
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sadly so Deepak! But to be fair I think there are errors in most technical books!

Rufus.
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rufus
My understanding is that there will always be a seperate occurance of the Classic Tag handler per thread.

So for example if two threads invoke the classic tag, then there will be two instances of the classic tag handler available, and the member variables will affectively be thread safe.


I guess this would not hold true for thread level pooling of classic tags. Please see Restrictions on tag handler reuse in http://www.ibm.com/developerworks/websphere/techjournal/0403_johnson/0403_johnson.html#sec3
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic