You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by "Kumar, Kiran" <kk...@kheaa.com> on 2005/04/16 21:04:56 UTC

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

Posted by Torsten Curdt <tc...@apache.org>.
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