From: Roedy Green on
The IntelliJ code Inspector (lint) slapped my wrist for synchronising
on a local variable. What's the problem with that? The sync is on
the object, not the reference, right?
--
Roedy Green Canadian Mind Products
http://mindprod.com

Don�t worry about people stealing an idea; if it�s original, you�ll have to shove it down their throats.
~ Howard Aiken (born: 1900-03-08 died: 1973-03-14 at age: 73)
From: markspace on
Roedy Green wrote:
> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
> on a local variable. What's the problem with that? The sync is on
> the object, not the reference, right?


Need SSCCE.

http://sscce.org/

From: Arved Sandstrom on
Roedy Green wrote:
> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
> on a local variable. What's the problem with that? The sync is on
> the object, not the reference, right?

Each thread gets its own local variable. Defeats the purpose of
synchronizing on one.

AHS
From: markspace on
Arved Sandstrom wrote:
> Roedy Green wrote:
>> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
>> on a local variable. What's the problem with that? The sync is on
>> the object, not the reference, right?
>
> Each thread gets its own local variable. Defeats the purpose of
> synchronizing on one.


If you later export that local reference to another thread or object, it
should be fine. It's valid to synchronize on a object that some other
part of the system will see later.

If you just synchronized on a local variable and then let it go out of
scope, yeah, that's a pretty serious "D'oh!" moment.

From: Arne Vajhøj on
On 24-03-2010 18:11, Roedy Green wrote:
> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
> on a local variable. What's the problem with that? The sync is on
> the object, not the reference, right?

Local variables are thread specific.

Passing on a local variable to another thread via some
global variable/singleton/cache would be a pretty bad design.

I can understand the complaint.

Arne

PS: yes - it is the object not the ref.