cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kumar, Kiran" <kku...@kheaa.com>
Subject RE: Problem with sharing sessions/ multithreading
Date Sat, 16 Apr 2005 20:20:10 GMT
 

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:tcurdt@apache.org]
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

Mime
View raw message