[EMAIL PROTECTED] escribió:
> 
> The init method is synchronized - is there a particular reason for this ?
> I looked at some other JetSpeed services, their init method was not
> synchronized.
> 

It is part of the workaround for the bug in the turbine.jar we are using
right now. We can get rid of it when we update turbine, although it
should do no harm, as it is executed only once per life cycle.

The idea is:

If somebody calls init( conf ) twice, the second caller will wait until
the first finishes (synchronized). When the first finishes, either:

getInit() will return true (we are already initialized), so the second
thread returns.
getInit() will return false (we failed previously), so we try again in
the second thread.

To further complicate the picture, a third thread can ask for the
service while these two (or more) threads are "fighting" to initialize
the service. In case a service is asked for and getInit() returns false,
turbine will call late init(). There we must wait until getInit()
returns true. (the previous impl did not implement this call, and
BaseService did setInit(true), returning a half-cooked service to the
caller).

I made a mistake when I synchronized late init() and at the same time
waited there. This locked up turbine if some thread asked for the
service (late init) BEFORE early init was called. This thread got the
lock, and waited for something impossible to happen. Has I use
wait()/notifyAll() instead of sleep() it would have worked. Currently,
late init() is not synchronized, and waits for early init(conf) to
finish.

When we can be sure that turbine will call us only once (when we update
to a more current release), we can get rid of both the synchronized and
the if(getInit() ) return; (although I think they are not expensive and
do no harm).

I hope I explain it correctly. It took me quite a few hours to
understand what was going on there ;)


--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/[email protected]/>
List Help?:          [EMAIL PROTECTED]

Reply via email to