You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by llama-king <p....@albourne.com> on 2012/05/21 11:08:55 UTC

[t5.3.x] Potential Static Util Class Concurrency Issue

Hello,

First post! Woo!

While using various revisions of T5.3 we ran into a strange case as follows:

1. User A fills in text field, submits form.
2. User B fills in text field, submits form.
(Where 1 and 2 occur within milliseconds of each other.)

3. Events trigger, util class static method called.

4. User A's query is passed to util class, result returned to User B.
(User B has intercepted  User  A's result.)

This occurred a while ago and was rectified by stripping away the static.
I'm 
just wondering if anyone is familiar with this scenario and/or would have
any 
ideas of a potential work-around or fix?

Thanks!
Peter





--
View this message in context: http://tapestry.1045711.n5.nabble.com/t5-3-x-Potential-Static-Util-Class-Concurrency-Issue-tp5712809.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: [t5.3.x] Potential Static Util Class Concurrency Issue

Posted by Lance Java <la...@googlemail.com>.
FYI you can call
PerthreadManager.addThreadCleanupListener(ThreadCleanupListener listener) to
cleanup any ThreadLocals. Tapestry fires the listeners at the end of each
request.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/t5-3-x-Potential-Static-Util-Class-Concurrency-Issue-tp5712809p5712869.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: [t5.3.x] Potential Static Util Class Concurrency Issue

Posted by Howard Lewis Ship <hl...@gmail.com>.
On Mon, May 21, 2012 at 4:54 AM, Bryan Lewis <jb...@gmail.com> wrote:
> I experienced a fourth possibility, although it could be considered a
> variant of the third one.  I was storing an object map (a Cayenne
> ObjectContext) in a ThreadLocal and I wasn't clearing the ThreadLocal
> immediately at the end of each request.  In rare circumstances, when a
> second user started a request at the same time another request ended, the
> second user could see the first one's objects.  App servers (Jetty in my
> case) generally use thread pooling.

You should use the PerthreadManager service, and have it create a
PerThreadValue for you.  The PerThreadValue can be saved and used
across threads, but the value is stored inside a single Map that is
managed by Tapestry and therefore properly cleared at the end of the
request.

http://tapestry.apache.org/5.3.3/apidocs/org/apache/tapestry5/ioc/services/PerthreadManager.html

>
>
>
> On Mon, May 21, 2012 at 5:36 AM, Lance Java <la...@googlemail.com>wrote:
>
>> Without seeing any code it's hard to tell but there are only a couple of
>> ways
>> for user A to see user B's data.
>>
>> 1. You have initialized a page/component variable in the field declaration
>> (or the constructor). This is the most likely candidate. Mutable objects
>> MUST NOT be initialized in the field declaration or constructor and must be
>> initialized in onActivate() / beginRender() etc.
>>
>> 2. You have a mutable static variable (almost always a bad idea)
>>
>> 3. You have a mutable variable on a singleton service (again, most of the
>> time this is a bad idea).
>>
>> --
>> View this message in context:
>> http://tapestry.1045711.n5.nabble.com/t5-3-x-Potential-Static-Util-Class-Concurrency-Issue-tp5712809p5712819.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: [t5.3.x] Potential Static Util Class Concurrency Issue

Posted by Bryan Lewis <jb...@gmail.com>.
I experienced a fourth possibility, although it could be considered a
variant of the third one.  I was storing an object map (a Cayenne
ObjectContext) in a ThreadLocal and I wasn't clearing the ThreadLocal
immediately at the end of each request.  In rare circumstances, when a
second user started a request at the same time another request ended, the
second user could see the first one's objects.  App servers (Jetty in my
case) generally use thread pooling.



On Mon, May 21, 2012 at 5:36 AM, Lance Java <la...@googlemail.com>wrote:

> Without seeing any code it's hard to tell but there are only a couple of
> ways
> for user A to see user B's data.
>
> 1. You have initialized a page/component variable in the field declaration
> (or the constructor). This is the most likely candidate. Mutable objects
> MUST NOT be initialized in the field declaration or constructor and must be
> initialized in onActivate() / beginRender() etc.
>
> 2. You have a mutable static variable (almost always a bad idea)
>
> 3. You have a mutable variable on a singleton service (again, most of the
> time this is a bad idea).
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/t5-3-x-Potential-Static-Util-Class-Concurrency-Issue-tp5712809p5712819.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: [t5.3.x] Potential Static Util Class Concurrency Issue

Posted by Lance Java <la...@googlemail.com>.
Without seeing any code it's hard to tell but there are only a couple of ways
for user A to see user B's data.

1. You have initialized a page/component variable in the field declaration
(or the constructor). This is the most likely candidate. Mutable objects
MUST NOT be initialized in the field declaration or constructor and must be
initialized in onActivate() / beginRender() etc.

2. You have a mutable static variable (almost always a bad idea)

3. You have a mutable variable on a singleton service (again, most of the
time this is a bad idea).

--
View this message in context: http://tapestry.1045711.n5.nabble.com/t5-3-x-Potential-Static-Util-Class-Concurrency-Issue-tp5712809p5712819.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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