You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Samppa Saarela <Sa...@cs.Helsinki.FI> on 2004/10/07 17:20:24 UTC

Multiple globals created

Hi,

It seems that in case the constructor of global is time consuming 
Tapestry might create multiple globals. I run into this when I tried to 
initialize Lucene (build the index) inside the globals constructor to 
avoid synchronization overhead later. If user hit reload before the 
constructor had first finished, Tapestry creates a new global which in 
this case ends up in an un caught exception since two threads are 
accessing the same index files. Now I can get around this so that the 
user never knows something has gone wrong - only a series IOExceptions 
are logged - but having the global truely singleton would be much 
cleaner and better solution. I'm using Tapestry 3.0 on  a Windows XP 
with Java 1.5.

Regards
  Samppa


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Multiple globals created

Posted by Samppa Saarela <Sa...@cs.Helsinki.FI>.
Thanks for this reference. Unfortunately it doesn't help in this 
situation: the problem is that the global gets created multiple times in 
the first place - in which synchronizing the createGlobal -method 
doesn't help. It seems to me that this is a thing that can be resolved 
only "inside Tapestry".

The problem lies in the method 
AbstractEngine#setupForRequest(RequestContext) at lines 1384-1391 
(@version $Id: AbstractEngine.java,v 1.30 2004/04/06 16:26:58 hlship Exp 
$).

<clip>
_global = servletContext.getAttribute(name);

if (_global == null)
{
  _global = createGlobal(context);

  servletContext.setAttribute(name, _global);
}
</clip>

should be something like this

<clip>
synchronized (servletContext)
{
  _global = servletContext.getAttribute(name);

  if (_global == null)
  {
    _global = createGlobal(context);

    servletContext.setAttribute(name, _global);
  }
}
</clip>

I'd suggest synchronizing all the other initializations in that method 
also since how ever rare this kind of race conditions that actually 
cause problems are they do occur eventually - and cause problems.

Of course this kind of synchronization causes performance loss so maybe 
not everyone would wellcome this kind of (overkill?) robustness.

So any opinions: should I 1) fix this in my own engine class, 2) fix it 
to the cvs head (or what ever the 3.0 branch is) and (try to find out 
how to) commit it, 3) stop using global and start using application 
extensions (are those truly singleton?) or 4) will this be addressed by 
Tapestry developers in the near future - by 3.1 and Hivemind perhaps?

Regards
   Samppa

----- Original Message ----- 
From: "Bryan Lewis" <br...@maine.rr.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Thursday, October 07, 2004 7:35 PM
Subject: Re: Multiple globals created


> This earlier posting should help.
>
> http://www.caddr.com/macho/archives/tapestry-users/2004-2/4420.html
>
>
> ----- Original Message ----- 
> From: "Samppa Saarela" <Sa...@cs.Helsinki.FI>
> To: "Tapestry users" <ta...@jakarta.apache.org>
> Sent: Thursday, October 07, 2004 11:20 AM
> Subject: Multiple globals created
>
>
>> Hi,
>>
>> It seems that in case the constructor of global is time consuming
>> Tapestry might create multiple globals. I run into this when I tried 
>> to
>> initialize Lucene (build the index) inside the globals constructor to
>> avoid synchronization overhead later. If user hit reload before the
>> constructor had first finished, Tapestry creates a new global which 
>> in
>> this case ends up in an un caught exception since two threads are
>> accessing the same index files. Now I can get around this so that the
>> user never knows something has gone wrong - only a series 
>> IOExceptions
>> are logged - but having the global truely singleton would be much
>> cleaner and better solution. I'm using Tapestry 3.0 on  a Windows XP
>> with Java 1.5.
>>
>> Regards
>>   Samppa
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: 
>> tapestry-user-help@jakarta.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Multiple globals created

Posted by Bryan Lewis <br...@maine.rr.com>.
This earlier posting should help.

http://www.caddr.com/macho/archives/tapestry-users/2004-2/4420.html


----- Original Message ----- 
From: "Samppa Saarela" <Sa...@cs.Helsinki.FI>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Thursday, October 07, 2004 11:20 AM
Subject: Multiple globals created


> Hi,
> 
> It seems that in case the constructor of global is time consuming 
> Tapestry might create multiple globals. I run into this when I tried to 
> initialize Lucene (build the index) inside the globals constructor to 
> avoid synchronization overhead later. If user hit reload before the 
> constructor had first finished, Tapestry creates a new global which in 
> this case ends up in an un caught exception since two threads are 
> accessing the same index files. Now I can get around this so that the 
> user never knows something has gone wrong - only a series IOExceptions 
> are logged - but having the global truely singleton would be much 
> cleaner and better solution. I'm using Tapestry 3.0 on  a Windows XP 
> with Java 1.5.
> 
> Regards
>   Samppa
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org