• 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

tagSupport and synchronization issues

 
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, could someone help me here please? I have issues with Tomcats JSP's tagSupport-type customtags and synchronization. With servlets synchronization problems raise with simultoneus usage of instance (or class) variables, eg. if variable is declared inside class declaration instead of declaration inside method (like doGet/doPost). So, if variable is declared inside method (like doGet), no problems can occure. Now, when JSP is loaded first time it is turned into servlet, so same rules are valid here also ==> if variable is declared inside _jspService-method, no problems can occur.

Example codes are listed below..

Every variable declared in JSP-page is declared in the jsp_service-method except those declared with <%@ (=directives) or with <%! (=declarations) which are declared inside class declaration. So, problems may raise when variables are declared with these scripts. Now the interesting point is that tag-libraries are used with <%@ -scripts, so problems may raise. If we look at source-code of the JSP/Servlet-class (which is generated when JSP is loaded first time) we can see that HttpJspBase (which JSP extends) has TagHandlerPool-type of instance variable called something like _jspx_tagPool_mytag_hello ==>



here's pack.HelloWorldTag..


here's the jsp-page (hellotest.jsp)

<%@taglib uri="/hello" prefix="mytag" %>
<html>
<head><title>JSP Page</title>
</head>
<body>
<mytag:hello/>
</body>
</html>

I've used this piece of code to test whether code is thread-safe. I have made simple HTML-page which has many framesets and each of them includes hellotest.jsp. This way I try to simulate simultoneous use..Now the alarming point is that on some cases excatly same numbers are printed on different framesets! On same cases when I refresh screen same numbers are printed again! I think it is because of the delay created on the tagSupport-class because if I take delay off then everything seems to work just fine..but that delay is actually quite truelike if I may say..delays can occur even if programmer doesn't cause them explicitly..But here's my question, what causes this kind of strange behaviour? Can it be fixed somehow? I tried to fix it by putting the contents of the doStartTag and doEndTag inside synchronized(this) block. It didn't work. Any pieces of advice/information is greatly appreciated..Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tgas do not need to be synchronized since each page will get their own instance(s) of the tag. Any problem you might be having (which I cannot understand from your description) lies elsewhere.
 
reply
    Bookmark Topic Watch Topic
  • New Topic