You're quite right,
I was aware of this, but trying to be as clear as possible.
Thanks for you input
-matt
On Fri, Jun 01, 2001 at 06:09:59PM -0700, Simon Waddington wrote:
> This is kind of late in the conversation... but there's a race condition in
> your code. The thread that finds initialized zero could get suspended
> before setting it to one. Its unlikely but could happen. Then another
> thread will also find it zero and both threads will end up performing
> initialization.
>
> Code modifying shared data should be synchronized to achieve "test and set"
> semantics:
>
> <xsp:page>
> <xsp:logic>
> boolean initialized = false;
> public synchronized void doInitialization () {
> if (!initialized) {
> // Do initialization here
>
> // if init code successful (assuming it can fail)
> initialized = true;
> }
> }
> </xsp:logic>
>
> <page>
> <xsp:logic>
> doInitialization ();
>
> // rest of page
> </xsp:logic>
> </xsp:page>
>
> If you don't like the method call overhead then make the variable an object
> and synchronize the section around the test-and-set operation on it - or one
> some other appropriate object. In this case syncrhonization may seem like
> a pain in the butt, but without it once in a blue moon your code will fail -
> if initializing twice on those blue moon occasions isn't a big deal then
> throw caution to the wind and leave it out, otherwise I'm afraid you'll need
> it.
>
>
> -----Original Message-----
> From: Matthew Cordes [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 01, 2001 1:12 PM
> To: [EMAIL PROTECTED]
> Subject: Re: init() and destroy() in XSP
>
>
> There is no init method, i'm just suggesting:
>
> <xsp:page>
> <xsp:logic>
> int initialized = 0;
> </xsp:logic>
>
> <page>
> <xsp:logic>
> if ( initialized == 0 )
> {
> // do init stuff here
>
> initialized = 1; // this block will never be reached again.
> }
> </xsp:logic>
> </page>
> </xsp:page>
>
> Hope this helps. Perhaps someone else has another idea?
>
> -matt
>
>
> ----- Original Message -----
> From: "Frans Thamura" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, June 01, 2001 1:24 AM
> Subject: Re: init() and destroy() in XSP
>
>
> > Matt,
> > I don't understand, I need your help.
> >
> > I create a lot of xsp:page, but never find init()
> > Would you give the simple work sample?
> >
> > Frans
> > ----- Original Message -----
> > From: "Matthew Cordes" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Friday, June 01, 2001 3:01 PM
> > Subject: Re: init() and destroy() in XSP
> >
> >
> > > There are work-arounds though:
> > >
> > > INIT:
> > > Make a global variable, set it to null, inside your <xsp:page> block
> check
> > > to see if it is null and do init stuff, then set it to something else.
> > >
> > > DESTROY:
> > > wouldn't overloading void finalize() { ... } work here?
> > >
> > > -matt
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Frans Thamura" <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Thursday, May 31, 2001 11:38 PM
> > > Subject: Re: init() and destroy() in XSP
> > >
> > >
> > > > Ya, one of cocoon problem is no init and destroy
> > > >
> > > > ----- Original Message -----
> > > > From: "Polley Christopher W" <[EMAIL PROTECTED]>
> > > > To: <[EMAIL PROTECTED]>
> > > > Sent: Friday, May 04, 2001 9:16 PM
> > > > Subject: init() and destroy() in XSP
> > > >
> > > >
> > > > > Hello, all:
> > > > >
> > > > > I have an XSP page in which I would like to do some setup (open
> JDBC
> > > > > connection, create prepared statements) upon instantiation and
> cleanup
> > > > > (close ps's and connection) upon destruction.
> > > > >
> > > > > In its previous life as a jsp page, it used jspInit() and
> > jspDestroy(),
> > > > and
> > > > > in a servlet it could use init() and destroy().
> > > > >
> > > > > I found XSPPage.init(parameters), which I can override to do the
> > > > > initialization, but I am unclear on the tail end of the xsp life
> > cycle.
> > > > How
> > > > > & when is it destroyed (in Cocoon 1.8.1) ? How is this type of
> thing
> > > done
> > > > > in XSP?
> > > > >
> > > > > I suppose that in this case, in which I am only doing JDBC stuff, I
> > > could
> > > > > try the sql taglib, but am unclear on how that would be done. Can
> > > > > <?cocoon-process type="sql"?> safely be placed ahead of
> > <?cocoon-process
> > > > > type="xsp"?>? What would the resultant xsp-servlet look like?
> > > > >
> > > > >
> > > > > Thanks,
> > > > > Chris
> > > > >
> > > > >
> > > >
> > ---------------------------------------------------------------------
> > > > > Please check that your question has not already been answered in the
> > > > > FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> > > > >
> > > > > To unsubscribe, e-mail: <[EMAIL PROTECTED]>
> > > > > For additional commands, e-mail: <[EMAIL PROTECTED]>
> > > >
> > > >
> > > > _________________________________________________________
> > > > Do You Yahoo!?
> > > > Get your free @yahoo.com address at http://mail.yahoo.com
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > Please check that your question has not already been answered in the
> > > > FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> > > >
> > > > To unsubscribe, e-mail: <[EMAIL PROTECTED]>
> > > > For additional commands, e-mail: <[EMAIL PROTECTED]>
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > Please check that your question has not already been answered in the
> > > FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> > >
> > > To unsubscribe, e-mail: <[EMAIL PROTECTED]>
> > > For additional commands, e-mail: <[EMAIL PROTECTED]>
> >
> >
> > _________________________________________________________
> > Do You Yahoo!?
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> > ---------------------------------------------------------------------
> > Please check that your question has not already been answered in the
> > FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> >
> > To unsubscribe, e-mail: <[EMAIL PROTECTED]>
> > For additional commands, e-mail: <[EMAIL PROTECTED]>
> >
>
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <[EMAIL PROTECTED]>
> For additional commands, e-mail: <[EMAIL PROTECTED]>
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <[EMAIL PROTECTED]>
> For additional commands, e-mail: <[EMAIL PROTECTED]>
>
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>