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: Problem with sharing sessions/ multithreading
Kumar, Kiran wrote: also in the following pipeline, how can I display a html page after the homepage action is called? right here I need to call a HTML page Kumar, Please try to limit how much of previous messages you quote. In the case above, create a resource definition and then call it inside your map:act. Ralph
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: 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? right here I need to call a HTML page 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? right here I need to call a HTML page 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
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
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
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
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
Kumar, Kiran wrote: > could you please let me know more about DCL? Did you have a look into the javaworld article? cheers -- Torsten signature.asc Description: OpenPGP digital signature
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
> 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 signature.asc Description: OpenPGP digital signature
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
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: 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 signature.asc Description: OpenPGP digital signature
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