Hi Nathan,
I can't comment on whether or not the synchronization should occur (not
being a regular Tools user), but I hit this problem in a project and got
stung when I falsely assumed you could synchronize using the session object.
This was a particular concern for me with web apps using frames, as the
multiple frames will simultaneously make HTTP requests. My experience was a
classic intermittent failure problem where the system worked on my dev
server but not on the client's server-- a very frustrating debugging
experience.
The solution was to make my own simple session mutex, and then synchronize
on that object. Maybe this could be useful.
/**
* Get an object that can be synchronized across a session.
*/
public Object getSessionMutex()
{
Object ret = session.getAttribute(SESSION_MUTEX_ATTRIBUTE);
if (ret == null) {
ret = new Boolean(true);
session.setAttribute(SESSION_MUTEX_ATTRIBUTE,ret);
}
return ret;
}
You can then use this with:
Object mutex = getSessionMutex();
synchronized (mutex) {
some code
}
Best, WILL
----- Original Message -----
From: "Nathan Bubna" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, January 29, 2004 2:18 PM
Subject: [veltools] session tool init and synchronization
> hey folks, i'm looking for some feedback on this...
>
> at issue is the synchronization of session tools initialization in
> ServletToolboxManager.getToolboxContext(). the reason we have tried to
> synchronize this block of code is to avoid multiple initializations of
> session-scoped tools in situations where multiple simultaneous requests
are
> received from the same browser. (for background, see
> http://marc.theaimsgroup.com/?l=velocity-dev&m=101837293614981&w=2 and the
> subsequent responses in the thread).
>
> the problem i'm now looking at is that it is apparently pointless to try
> synchronizing on the session instance itself as the code currently does.
(for
> discussion of this, see
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19223).
>
> so, it seems to me that really only leaves us with two options:
>
> -synchronize on the ServletToolboxManager instance. this will work, but
is a
> heavier-handed approach because it will allow session tools to be
initialized
> for only one session at a time, not just once per session.
>
> -don't synchronize at all and leave it to the tool developer to be
concerned
> (or not) about whether the chance of initializing session tools multiple
times
> for the same session matters.
>
> personally, i'm inclined to the second. in my personal experience, few
> session tools are used and initialization of them is not generally costly,
nor
> would it be screwed up by happening multiple times for one user/session.
on
> top of that, the likelihood of mutliple-near simultaneous requests at
session
> initialization is quite low (especially for me since i don't use framesets
in
> my projects).
>
> so, i guess my primary question is whether or not anyone else concerned
about
> this?
>
> since the current synchronization is ineffective and i haven't heard news
of
> any problems, i'm guessing that the answer is "no," or at least "not so
far."
> as such, i'm going to go ahead and remove the synchronization for now.
but i
> wanted to put this out there to give people a heads up, see if this issue
is a
> real concern for anyone, and get any other thoughts on the matter.
>
> Nathan Bubna
> [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]