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 OK    this 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;
}

Reply via email to