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.