RE: Unsubscribe
ubsubscribe
RE: Problem with sharing sessions/ multithreading
could you please let me know more about DCL? and regarding posting 5 times.. that was done by mistake. thanks Kiran Kumar (502) 696-7203 -Original Message- From: Torsten Curdt [mailto:[EMAIL PROTECTED] Sent: Sunday, April 17, 2005 7:18 AM To: dev@cocoon.apache.org Subject: Re: Problem with sharing sessions/ multithreading 1. Is it my imagination or was the same message posted 5 times? Nope, that was real ...plus the direct To:s method from all your actions to get the document. It should do something like: Don't want to be picky ...but better don't use DCL http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-double.html cheers -- Torsten
RE: Problem with sharing sessions/ multithreading
Hi ,, thanks for the quick response.. I have coded this DCL logic and I am testing this and let you know. 1. there was some issue with my inbox and it posted somany times 2. yes. multiple users login at the same time and get the same DOM. but when I refresh the page the xml and screen is OKthis is the trick part of the whole problem. which I never understood I hope the DCL fixes this?? part of the solution I had found was to use Filter to filter all the requests as below public void doFilter( ServletRequest request, ServletResponse response, FilterChain filterChain) { try { request.setCharacterEncoding(GB2312); ((HttpServletResponse) response).setHeader(Cache-control,no-cache); ((HttpServletResponse) response).setHeader(Pragma, No-cache); ((HttpServletResponse) response).setHeader(Expires, 0); filterChain.doFilter(request, response); } catch (ServletException sx) { filterConfig.getServletContext().log(sx.getMessage()); } catch (IOException iox) { filterConfig.getServletContext().log(iox.getMessage()); } } - regarding the Question 2 a), some part of the XML never changes. The other part changes based on the user actions. I am going through 15-20 database files to build part one and atleast 5-6 database files to build the part 2. so when login, I build both parts but do not refresh the first part as student does not change it. thanks Kiran Kumar (Raj) (502) 696-7203 -Original Message- From: Ralph Goers [mailto:[EMAIL PROTECTED] Sent: Sunday, April 17, 2005 1:34 AM To: dev@cocoon.apache.org Subject: Re: Problem with sharing sessions/ multithreading 1. Is it my imagination or was the same message posted 5 times? 2. If I understand correctly, the problem is that multiple users are getting the same DOM object? a. Question: Why do you have two actions that do essentially the same thing? b. By the way, even though you declared them ThreadSafe they clearly are not. It is possible for the web-browser to issue two requests at the same time to Cocoon for the same user, depending on how the html page is constructed, in which case both of these actions could execute at the same time. c. What is the purpose of synchronizing the object returned by newInstance? That is a local variable and if each call to newInstance returns a different object, this will accomplish nothing. If you want to serialize the call to newDocument then you should refactor this whole block of code in a method in a utility class and then always call that method from all your actions to get the document. It should do something like: private static final String LOCK = Lock; Document getDocument() { Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); Document doc = (Document)session.getAttribute(myAttribute); if (doc == null) { // It is possible for more than one thread to get here at the same time with doc == null syncronize(LOCK); { // So check again. Only the first caller should actually create the document. doc = (Document)session.getAttribute(myAttribute); if (doc == null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); doc = dbf.newDocumentBuilder().newDocument(); session.setAttribute(myAttribute, doc); } } } return doc; }
RE: Problem with sharing sessions/ multithreading
yes I did thanks Kiran Kumar (502) 696-7203 -Original Message- From: Torsten Curdt [mailto:[EMAIL PROTECTED] Sent: Sunday, April 17, 2005 11:47 AM To: dev@cocoon.apache.org Subject: Re: Problem with sharing sessions/ multithreading Kumar, Kiran wrote: could you please let me know more about DCL? Did you have a look into the javaworld article? cheers -- Torsten
RE: Problem with sharing sessions/ multithreading
here's what I did. and changing all the code to use this. == private static final String LOCK = Lock; public Document getDocument(Map objectModel,String attrname) throws ParserConfigurationException { Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); Document doc = (Document)session.getAttribute(attrname); if (doc == null) { // It is possible for more than one thread to get here at // the same time with doc == null synchronized(LOCK) { // So check again. Only the first caller should // actually create the document. doc = (Document)session.getAttribute(attrname); if (doc == null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); doc = dbf.newDocumentBuilder().newDocument(); session.setAttribute(attrname, doc); } } } return doc; } = but why do we need static method?? please guide me thanks Kiran Kumar (Raj) (502) 696-7203 -Original Message- From: Ralph Goers [mailto:[EMAIL PROTECTED] Sent: Sunday, April 17, 2005 12:27 PM To: dev@cocoon.apache.org Subject: Re: Problem with sharing sessions/ multithreading Torsten Curdt wrote: Don't want to be picky ...but better don't use DCL http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-double.html cheers Thanks, that article wasn't too helpful in figuring out why the technique doesn't work. However, it refreences an article from Alan Holub that does. From his description, the following version of the DCL should work fine. I'm not sure the function actually has to be static. From what I could tell synchronized should be sufficient. Document getDocument() { Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); Document doc = (Document)session.getAttribute(myAttribute); if (doc == null) { // It is possible for more than one thread to get here at the same time with doc == null syncronize(LOCK); { // So check again. Only the first caller should actually create the document. doc = (Document)session.getAttribute(myAttribute); if (doc == null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); doc = buildDocument(dbf); session.setAttribute(myAttribute, doc); } } } return doc; } private static synchronized Document buildDocument(DocumentBuilderFactory dbf) { return dbf.newDocumentBuilder().newDocument(); } -- Torsten
RE: Problem with sharing sessions/ multithreading
also in the following pipeline, how can I display a html page after the homepage action is called? map:handle-errors map:select type=exception map:when test=processing map:act type=home-page right here I need to call a HTML page /map:act /map:when /map:select /map:handle-errors thanks Kiran Kumar (Raj) (502) 696-7203 -Original Message- From: Ralph Goers [mailto:[EMAIL PROTECTED] Sent: Sunday, April 17, 2005 12:27 PM To: dev@cocoon.apache.org Subject: Re: Problem with sharing sessions/ multithreading Torsten Curdt wrote: Don't want to be picky ...but better don't use DCL http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-double.html cheers Thanks, that article wasn't too helpful in figuring out why the technique doesn't work. However, it refreences an article from Alan Holub that does. From his description, the following version of the DCL should work fine. I'm not sure the function actually has to be static. From what I could tell synchronized should be sufficient. Document getDocument() { Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); Document doc = (Document)session.getAttribute(myAttribute); if (doc == null) { // It is possible for more than one thread to get here at the same time with doc == null syncronize(LOCK); { // So check again. Only the first caller should actually create the document. doc = (Document)session.getAttribute(myAttribute); if (doc == null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); doc = buildDocument(dbf); session.setAttribute(myAttribute, doc); } } } return doc; } private static synchronized Document buildDocument(DocumentBuilderFactory dbf) { return dbf.newDocumentBuilder().newDocument(); } -- Torsten
RE: Problem with sharing sessions/ multithreading
looks like the Filter works but not all the time.. private FilterConfig filterConfig; //Handle the passed-in FilterConfig public void init(FilterConfig filterConfig) { this.filterConfig = filterConfig; } //Process the request/response pair public void doFilter( ServletRequest request, ServletResponse response, FilterChain filterChain) { try { request.setCharacterEncoding(GB2312); ((HttpServletResponse) response).setHeader(Cache-control,no-cache); ((HttpServletResponse) response).setHeader(Pragma, No-cache); ((HttpServletResponse) response).setHeader(Expires, 0); filterChain.doFilter(request, response); } catch (ServletException sx) { filterConfig.getServletContext().log(sx.getMessage()); } catch (IOException iox) { filterConfig.getServletContext().log(iox.getMessage()); } } //Clean up resources public void destroy() { Is there any thing else I need to do to make this filter not Cache all time. In test, till now I was logging as the same user in 2 systems , logout, access account, hit back button and login again. It displays the correct information. now I switched users after logout.. and it displays correct information. But the problem is when I hit refresh, it displayed the information of the previous user.. any clues on this thanks Kiran Kumar (Raj) (502) 696-7203 -Original Message- From: Kumar, Kiran Sent: Sunday, April 17, 2005 12:47 PM To: 'dev@cocoon.apache.org' Subject: RE: Problem with sharing sessions/ multithreading also in the following pipeline, how can I display a html page after the homepage action is called? map:handle-errors map:select type=exception map:when test=processing map:act type=home-page right here I need to call a HTML page /map:act /map:when /map:select /map:handle-errors thanks Kiran Kumar (Raj) (502) 696-7203 -Original Message- From: Ralph Goers [mailto:[EMAIL PROTECTED] Sent: Sunday, April 17, 2005 12:27 PM To: dev@cocoon.apache.org Subject: Re: Problem with sharing sessions/ multithreading Torsten Curdt wrote: Don't want to be picky ...but better don't use DCL http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-double.html cheers Thanks, that article wasn't too helpful in figuring out why the technique doesn't work. However, it refreences an article from Alan Holub that does. From his description, the following version of the DCL should work fine. I'm not sure the function actually has to be static. From what I could tell synchronized should be sufficient. Document getDocument() { Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); Document doc = (Document)session.getAttribute(myAttribute); if (doc == null) { // It is possible for more than one thread to get here at the same time with doc == null syncronize(LOCK); { // So check again. Only the first caller should actually create the document. doc = (Document)session.getAttribute(myAttribute); if (doc == null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); doc = buildDocument(dbf); session.setAttribute(myAttribute, doc); } } } return doc; } private static synchronized Document buildDocument(DocumentBuilderFactory dbf) { return dbf.newDocumentBuilder().newDocument(); } -- Torsten
RE: Problem with sharing sessions/ multithreading
I will try this.. because.. after using this utility class, I see sharing sessions more often. when I switched the users in the same browser. thanks Kiran Kumar (Raj) (502) 696-7203 -Original Message- From: Ralph Goers [mailto:[EMAIL PROTECTED] Sent: Sunday, April 17, 2005 1:07 PM To: dev@cocoon.apache.org Subject: Re: Problem with sharing sessions/ multithreading Kumar, Kiran wrote: here's what I did. and changing all the code to use this. == private static final String LOCK = Lock; public Document getDocument(Map objectModel,String attrname) throws ParserConfigurationException { Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); Document doc = (Document)session.getAttribute(attrname); if (doc == null) { // It is possible for more than one thread to get here at // the same time with doc == null synchronized(LOCK) { // So check again. Only the first caller should // actually create the document. doc = (Document)session.getAttribute(attrname); if (doc == null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); doc = dbf.newDocumentBuilder().newDocument(); session.setAttribute(attrname, doc); } } } return doc; } = but why do we need static method?? please guide me As Alan Holub pointed out, the JVM does not guarantee that the constructor for the Document returned by the call to newDocument() may not have been run at the time the Document object refrerence is assigned to the session attribute. Simply putting the call to newDocument() inside its own synchronized block should address that problem. Ralph
RE: Sharing sessions.. change to JDK1.5
but I am in trouble now as I cannot switch to 1.5 until some more time. It might take some time to migrate existing applications to 1.5. by the way we deploy the java on websphere AS400 thanks Kiran Kumar -Original Message- From: Torsten Curdt [mailto:[EMAIL PROTECTED] Sent: Sunday, April 17, 2005 1:14 PM To: Kumar, Kiran Subject: wrong mailing list? Kiran, Again: I don't really think the lock will solve your problem. This only helps if you have concurrent threads accessing the same session. Check the relation of the thread and the session id. As for the DCL: AFAIK this can *not* be solved in any (secure) way due to JVM internals - I though the article made that clear. The only way to do proper synchronization is synchronize all access ...or use Dough's concurrent utils (which are now also part of java 1.5) cheers -- Torsten
RE: Sharing sessions.. change to JDK1.5
does any give me an overview of what exactly I need to on using concurrent utils to create non-shareable DOM objects thanks Kiran Kumar (Raj) -Original Message- From: Ben Pope [mailto:[EMAIL PROTECTED] Sent: Sunday, April 17, 2005 2:44 PM To: dev@cocoon.apache.org Subject: Re: Sharing sessions.. change to JDK1.5 Kumar, Kiran wrote: From: Torsten Curdt The only way to do proper synchronization is synchronize all access ...or use Dough's concurrent utils (which are now also part of java 1.5) but I am in trouble now as I cannot switch to 1.5 until some more time. It might take some time to migrate existing applications to 1.5. by the way we deploy the java on websphere AS400 You can use the concurrent utils without going to java 1.5, as far as I know... they are packaged with cocoon now. But they come as standard with java 1.5. Ben
RE: Problem with sharing sessions/ multithreading
Hi all this is a problem I am working on. and I need to fix this ASAP. we have a website with thousands of users logging in to check their account information. we are using Cocoon 2.1 version. we also tried no-cache on all the stylesheets. It did not work and according to the Web-Team this is taking longer time to load the pages with lots of images. we had synchronized the code which creates the xml DOM objects using here is the action templates we use -- this is the first action which creates the documents. ++ public class XmlAction extends AbstractAction implements SingleThreaded { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); synchronized(dbf) { doc = dbf.newDocumentBuilder().newDocument(); } session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); return map; } } other actions use this session document to append/remove the elements + public class OtherAction extends AbstractAction implements ThreadSafe { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); doc = (Document)session.getAttribute(myAttribute); session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); return map; } } --- All the actions follow the same structure this session related issue. Here is an overview of what exactly happening. We developed web applications using Apache Cocoon framework. After user authenticates ( against custom registry database), I create a DOM object for the user with his account information and store in session. (I use cocoon SessionAttributeGenerator to transform the DOM to a HTML using XSL). Here the dom objects are being shared between sessions and I am seeing data from other users or processes. I used the synchronized blocks when creating xml doms from DocumentBuilderFactory newBuilder().newDocument() etc but it didnt fix the issue is there any way I can resolve this issue?? I found in the cocoon users group that by using the Java Filters with cocoon servlet fixed this problem? could you give me some examples about how to use the filters effectively appreciate your response. Also I can give more information required. thanks Kiran
RE: Problem with sharing sessions/ multithreading
Hi all this is a problem I am working on. and I need to fix this ASAP. we have a website with thousands of users logging in to check their account information. we are using Cocoon 2.1 version. we also tried no-cache on all the stylesheets. It did not work and according to the Web-Team this is taking longer time to load the pages with lots of images. we had synchronized the code which creates the xml DOM objects using here is the action templates we use -- this is the first action which creates the documents. ++ public class XmlAction extends AbstractAction implements SingleThreaded { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); synchronized(dbf) { doc = dbf.newDocumentBuilder().newDocument(); } session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); return map; } } other actions use this session document to append/remove the elements + public class OtherAction extends AbstractAction implements ThreadSafe { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); doc = (Document)session.getAttribute(myAttribute); session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); return map; } } --- All the actions follow the same structure this session related issue. Here is an overview of what exactly happening. We developed web applications using Apache Cocoon framework. After user authenticates ( against custom registry database), I create a DOM object for the user with his account information and store in session. (I use cocoon SessionAttributeGenerator to transform the DOM to a HTML using XSL). Here the dom objects are being shared between sessions and I am seeing data from other users or processes. I used the synchronized blocks when creating xml doms from DocumentBuilderFactory newBuilder().newDocument() etc but it didnt fix the issue is there any way I can resolve this issue?? I found in the cocoon users group that by using the Java Filters with cocoon servlet fixed this problem? could you give me some examples about how to use the filters effectively appreciate your response. Also I can give more information required. thanks Kiran
Sharring other people's information
Hi all this is a problem I am working on. and I need to fix this ASAP. we have a website with thousands of users logging in to check their account information. we are using Cocoon 2.1 version. we also tried no-cache on all the stylesheets. It did not work and according to the Web-Team this is taking longer time to load the pages with lots of images. we had synchronized the code which creates the xml DOM objects using here is the action templates we use -- this is the first action which creates the documents. ++ public class XmlAction extends AbstractAction implements SingleThreaded { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); synchronized(dbf) { doc = dbf.newDocumentBuilder().newDocument(); } session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); return map; } } other actions use this session document to append/remove the elements + public class OtherAction extends AbstractAction implements ThreadSafe { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); doc = (Document)session.getAttribute(myAttribute); session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); return map; } } --- All the actions follow the same structure this session related issue. Here is an overview of what exactly happening. We developed web applications using Apache Cocoon framework. After user authenticates ( against custom registry database), I create a DOM object for the user with his account information and store in session. (I use cocoon SessionAttributeGenerator to transform the DOM to a HTML using XSL). Here the dom objects are being shared between sessions and I am seeing data from other users or processes. I used the synchronized blocks when creating xml doms from DocumentBuilderFactory newBuilder().newDocument() etc but it didnt fix the issue is there any way I can resolve this issue?? I found in the cocoon users group that by using the Java Filters with cocoon servlet fixed this problem? could you give me some examples about how to use the filters effectively appreciate your response. Also I can give more information required. thanks Kiran thanks Kiran Kumar (Raj) (502) 696-7203
RE: Problem with sharing sessions/ multithreading
Hi this is a problem I am working on. and I need to fix this ASAP. we have a website with thousands of users logging in to check their account information. we are using Cocoon 2.1 version. we also tried no-cache on all the stylesheets. It did not work and according to the Web-Team this is taking longer time to load the pages with lots of images. we had synchronized the code which creates the xml DOM objects using here is the action templates we use -- this is the first action which creates the documents. ++ public class XmlAction extends AbstractAction implements SingleThreaded { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); synchronized(dbf) { doc = dbf.newDocumentBuilder().newDocument(); } session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); return map; } } other actions use this session document to append/remove the elements + public class OtherAction extends AbstractAction implements ThreadSafe { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); doc = (Document)session.getAttribute(myAttribute); session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); return map; } } --- All the actions follow the same structure this session related issue. Here is an overview of what exactly happening. We developed web applications using Apache Cocoon framework. After user authenticates ( against custom registry database), I create a DOM object for the user with his account information and store in session. (I use cocoon SessionAttributeGenerator to transform the DOM to a HTML using XSL). Here the dom objects are being shared between sessions and I am seeing data from other users or processes. I used the synchronized blocks when creating xml doms from DocumentBuilderFactory newBuilder().newDocument() etc but it didnt fix the issue is there any way I can resolve this issue?? I found in the cocoon users group that by using the Java Filters with cocoon servlet fixed this problem? could you give me some examples about how to use the filters effectively appreciate your response. Also I can give more information required. thanks Kiran -Original Message- From: Torsten Curdt [mailto:[EMAIL PROTECTED] Sent: Saturday, April 16, 2005 4:09 PM To: dev@cocoon.apache.org Subject: Re: Problem with sharing sessions/ multithreading Kumar, Kiran wrote: Hi all this is a problem I am working on. and I need to fix this ASAP. we have a website with thousands of users logging in to check their account information. we are using Cocoon 2.1 version. we also tried no-cache on all the stylesheets. It did not work and according to the Web-Team this is taking longer time to load the pages with lots of images. we had synchronized the code which creates the xml DOM objects using here is the action templates we use Kiran, please elaborate a bit more on the problem you are facing. BTW: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Since you create a new instance of the DBF there is no need for the synchronization. Only the access to the DBF is not guarantied to be threadsafe AFAIK. synchronized(dbf) { doc = dbf.newDocumentBuilder().newDocument(); } cheers -- Torsten
RE: Problem with sharing sessions/ multithreading
Hi this is a problem I am working on. and I need to fix this ASAP. we have a website with thousands of users logging in to check their account information. we are using Cocoon 2.1 version. we also tried no-cache on all the stylesheets. It did not work and according to the Web-Team this is taking longer time to load the pages with lots of images. we had synchronized the code which creates the xml DOM objects using here is the action templates we use -- this is the first action which creates the documents. ++ public class XmlAction extends AbstractAction implements SingleThreaded { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); synchronized(dbf) { doc = dbf.newDocumentBuilder().newDocument(); } session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); return map; } } other actions use this session document to append/remove the elements + public class OtherAction extends AbstractAction implements ThreadSafe { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); doc = (Document)session.getAttribute(myAttribute); session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); return map; } } --- All the actions follow the same structure this session related issue. Here is an overview of what exactly happening. We developed web applications using Apache Cocoon framework. After user authenticates ( against custom registry database), I create a DOM object for the user with his account information and store in session. (I use cocoon SessionAttributeGenerator to transform the DOM to a HTML using XSL). Here the dom objects are being shared between sessions and I am seeing data from other users or processes. I used the synchronized blocks when creating xml doms from DocumentBuilderFactory newBuilder().newDocument() etc but it didnt fix the issue is there any way I can resolve this issue?? I found in the cocoon users group that by using the Java Filters with cocoon servlet fixed this problem? could you give me some examples about how to use the filters effectively appreciate your response. Also I can give more information required. thanks Kiran -Original Message- From: Torsten Curdt [mailto:[EMAIL PROTECTED] Sent: Saturday, April 16, 2005 4:09 PM To: dev@cocoon.apache.org Subject: Re: Problem with sharing sessions/ multithreading Kumar, Kiran wrote: Hi all this is a problem I am working on. and I need to fix this ASAP. we have a website with thousands of users logging in to check their account information. we are using Cocoon 2.1 version. we also tried no-cache on all the stylesheets. It did not work and according to the Web-Team this is taking longer time to load the pages with lots of images. we had synchronized the code which creates the xml DOM objects using here is the action templates we use Kiran, please elaborate a bit more on the problem you are facing. BTW: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Since you create a new instance of the DBF there is no need for the synchronization. Only the access to the DBF is not guarantied to be threadsafe AFAIK. synchronized(dbf) { doc = dbf.newDocumentBuilder().newDocument(); } cheers -- Torsten
RE: [Authentication] - User with mixed Sessions
Thanks for all the information. here is what I started doing after some research To Start with here is the changes I did 1. stopped storing document in session. only root element is stored 2. here is the sample sitemap pipeline. I will give you complete sitemap when I go to office tomorrow morning when there xml needs to be built map:match . map:act type=xml map:generate type=session-attr map:parameter name=attr-name value=root/ /map:generate map:transform./ /map:act /map:match when not required map:match . map:generate type=session-attr map:parameter name=attr-name value=root/ /map:generate map:transform./ /map:match 3. To remove the caching problem, I started using a Filter and in the doFilter() method, I am setting the response.setHeader(Cache-control, no-cache) etc This filters all the requests coming to the web.xml 4. in the map:handle-errors/ pipeline in subsitemap, rebuilding the xml when user requests a URL from their bookmarks -- also I will follow the session creation rules.. but I am still not clear how to control the multithreading issue? please guide me in this -Original Message- From: Antonio Gallardo To: Kumar, Kiran Sent: 4/16/2005 9:32 PM Subject: RE: [Authentication] - User with mixed Sessions On Sab, 16 de Abril de 2005, 13:22, Kumar, Kiran dijo: HI Antonio, hi, greetings and thanks for quick response. this is a production problem I am working on. and I need to fix this ASAP. we have a website with thousands of users logging in to check their account information. we are using Cocoon 2.1 version. we Is posible to update to a newer version? Perhaps after 2.1.5.1? also tried no-cache on all the stylesheets. It did not work and according to the Web-Team this is taking longer time to load the pages with lots of images. I will like to see the sitemaps? And some generated pages. we had synchronized the code which creates the xml DOM objects using here is the action templates we use -- this is the first action which creates the documents. ++ public class XmlAction extends AbstractAction implements SingleThreaded { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); Try to use request.getSession(true) only in places where you are sure the user needs to create a new session. I remember to had problems with that. The same apply to the action below. Try to make a map where the use is going and use request.getSession(false) where you are sure the user already has a session. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); synchronized(dbf) { doc = dbf.newDocumentBuilder().newDocument(); } session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); session.setAttribute(student,student); return map; } } other actions use this session document to append/remove the elements + public class OtherAction extends AbstractAction implements ThreadSafe { /** * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters) */ public Map act(Redirector redirector,SourceResolver resolver,Map objectModel ,String source,Parameters parm) throws Exception { Map map = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); Session session = request.getSession(true); Same as above. doc = (Document)session.getAttribute(myAttribute); session.setAttribute(myAttribute, doc); session.setAttribute(root, sroot); session.setAttribute(student,student); return map; } } --- All the actions follow the same structure Are you tried to debug this part of the code? You can use eclipse to see step by step what is going on and keep track of the variables you think are causing troubles. Best Regards, Antonio Gallardo