cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ricardo Rocha <rica...@apache.org>
Subject Re: Are XSP Pages singletons?
Date Sat, 02 Sep 2000 03:08:18 GMT
Ed Staub wrote:
> The Servlet 2.2 spec says in section 2.3:
> "By default, there must be only one instance of a servlet class per servlet
> definition in a container..."

Similarily, there's only one instance of an XSP page class per Cocoon
session. This means all instance variables are shared across page
requests.

> ???????????????????????????????????????????????????????????????????
>   Is it possible for two threads to be running populateDocument() on the
> same instance of an XSP page concurrently?
> ???????????????????????????????????????????????????????????????????

The answer is yes: each thread spawned by the servlet engine to
serve an HTTP request will execute populateDocument(). This implies you
should take care of synchronizing access to critical instance variables
because they're shared.

Ricardo
==============================================================================
Ed Staub wrote:
> 
> Stefano and Matt,
> 
> I wrote earlier:
> 
> > In other words, can class variables be used dynamically without fear of
> > thread collision?
> 
> Sorry, I was not clear, let me try again!
> By "class variable" I meant "instance variable", i.e., a non-static variable
> declared at the class level.
> 
> Stefano wrote:
> 
> >And, anyway, servlets are not singletons at all: it's up to the
> >container to choose how many instances there are if you don't implement
> >SingleThreadModel (which is totally stupid and many of us on the Servlet
> >API JSR want to deprecate)
> 
> This has me really confused!
> 
> The Servlet 2.2 spec says in section 2.3:
> "By default, there must be only one instance of a servlet class per servlet
> definition in a container.  In the case of a servlet that implements the
> SingleThreadModel interface, the servlet container may instantiate multiple
> instances of that servlet so that it can handle a heavy request load while
> still serializing requests to a single instance.  In the case where a
> servlet was deployed as part of an application that is marked in the
> deployment descriptor as distributable, there is one instance of a servlet
> class per servlet definition per VM in a container. If the servlet
> implements the SingleThreadModel interface as well as is part of a
> distributable web application, the container may instantiate multiple
> instances of that servlet in each VM of the container."
> 
> So that's why I talked about singleton servlets.  Stefano, can you explain?
> Has normal practice advanced beyond the standard?
> 
> -----------
> 
> But what I _really_ wanted to ask was:
> 
> ???????????????????????????????????????????????????????????????????
>   Is it possible for two threads to be running populateDocument() on the
> same instance of an XSP page concurrently?
> ???????????????????????????????????????????????????????????????????
> 
> Obviously this is important to know in order to avoid writing invalid pages.
> All of the examples in the XSP doc would work either way, and the doc
> doesn't state whether it's a single-instance model or not.
> 
> In the proposal I floated earlier today ("RE: Aha! got it! 64k limit" from
> Fri 1 Sept 2000 3:27 PM) I created a PopulatingContext object to hold what
> are currently locals in populateDocument(), because I wasn't sure if it was
> safe to move some of the PopulateContext() locals into instance variables.
> Hence the question!
> 
> Thanks,
> -Ed Staub
> 
> -----Original Message-----
> From: Stefano Mazzocchi [mailto:stefano@apache.org]
> Sent: Friday, September 01, 2000 6:22 PM
> To: cocoon-users@xml.apache.org
> Subject: Re: Are XSP Pages singletons?
> 
> Ed Staub wrote:
> >
> > Are XSP pages singletons, like Servlets?
> >
> > In other words, can class variables be used dynamically without fear of
> > thread collision?
> 
> I wouldn't even dare trying: this is a sure way to get trouble in a
> server enviornment...
> 
> And, anyway, servlets are not singletons at all: it's up to the
> container to choose how many instances there are if you don't implement
> SingleThreadModel (which is totally stupid and many of us on the Servlet
> API JSR want to deprecate)
> 
> --
> Stefano Mazzocchi      One must still have chaos in oneself to be
>                           able to give birth to a dancing star.
> <stefano@apache.org>                             Friedrich Nietzsche
> --------------------------------------------------------------------
>  Missed us in Orlando? Make it up with ApacheCON Europe in London!
> ------------------------- http://ApacheCon.Com ---------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org

Mime
View raw message