• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classic tags handler scope

 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Question

the classic tags are pooled meaning the handlers are recycles
my question is do they recyle the handler within same request
or do they recyle handlers for different requests. Let say
request(1) call a.jsp and then request(2) call b.jsp then let say
a.jsp and b.jsp both call <prefix:myClassicTag /> should I expect
the state is kept between calls for a.jsp and b.jsp or b.jsp
will create anew handler for m"myClassicTag"

if that's the case when method release() is called?

thanks
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

custom tags are pooled does not mean that there is only one instance of the custopm tag. a.jsp and b.jsp can be use the same tag object or different tag object which is available in the pool. The custom tag preserved the state means it will not reset the values of instance/static variables etc. But if you have differnet parent and different Context for the tag invocation, the tag handler take care of this to set appropriate parent and tags attributes etc.

The Tag.release() called only when the container decide that the tag should no longer avilable in the service and should be garbage collected.

Correct me if anything wrong.

Thanks
 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer. I have other questions

Then should I initialize my Tag State in the
doStartTag() to make sure I am not taking
data from other request right?

Also

if a.jsp and b.jsp uses the same Tag-Handler
It may be a concurrency problem what if a and b
go into the container at the same time. Does
the container will create a new Tag-Handler
at that point to resolve the conflict? Because
I haven't seen nothing about synchronizing code
in a tag-handler

Finally I assume is upto the container when to
call release() but is this call guaranteed to
happen?
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then should I initialize my Tag State in the
doStartTag() to make sure I am not taking
data from other request right?

Absolutely! If you use instance variables, you should reset them in doStartTag() before an invocation or in doEndTag() after a previous invocation (I prefer the former).

Does the container will create a new Tag-Handler
at that point to resolve the conflict? Because
I haven't seen nothing about synchronizing code
in a tag-handler

Yes - the container guarantees that only one handler will be used at once for a tag invocation. Execution of a single handler instance will always run from doStartTag() to doEndTag() without any concurrency/threading issues.

Finally I assume is upto the container when to
call release() but is this call guaranteed to
happen?

Yes, just like garbage collection; it is guaranteed to happen, but of course this might not occur until container shut-down, depending on how the container's pooling mechanism works.
 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like the mechanism for classic tags is to create and destroy handlers
ondemand depending on the container needs. this is different to the servlet mechanism where we have one instance of the same servlet all the time.

I think the picture is getting clearer now

Thanks all to answer the questions
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic