Will Glass-Husain said:
> 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.

yeah, that's no fun.

> The solution was to make my own simple session mutex, and then synchronize
> on that object.  Maybe this could be useful.

i thought about just doing something like this too, but i'm not sure it's a
totally secure method either.  i'm by no means an expert in
threading/synchronization issues, but what about a two-thread scenario
where...

>     /** Get an object that can be synchronized across a session. */
>     public Object getSessionMutex()
>     {

where thread #2 gets to the following line:

>         Object ret = session.getAttribute(SESSION_MUTEX_ATTRIBUTE);
>         if (ret == null) {
>             ret = new Boolean(true);

while thread #1 is still in here and hasn't yet set the attribute

>             session.setAttribute(SESSION_MUTEX_ATTRIBUTE,ret);
>         }
>         return ret;
>     }
>
> You can then use this with:
>
>    Object mutex = getSessionMutex();
>    synchronized (mutex) {
>        some code
>    }

granted, your example would certainly be far more effective than synchronizing
on the session object, and in practice i'd imagine it would be *very* unlikely
to ever fail.  but it seems to me that this could still theoretically fail.
or am i missing/misunderstanding something?

Nathan Bubna
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to