From: Arne Vajhøj on 24 Mar 2010 21:25 On 24-03-2010 20:42, Roedy Green wrote: > On Wed, 24 Mar 2010 15:55:30 -0700, markspace<nospam(a)nowhere.com> > wrote, quoted or indirectly quoted someone who said : >> 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. > > I have a JTable. I get a row put it in a local variable and > synchronise on that. Does that not lock anyone else getting that > row, even if they have nothing to do with my local variable? It does. But the code would probably be difficult to read and this is why a code style checker flag it. Arne
From: Eric Sosman on 25 Mar 2010 00:06 On 3/24/2010 8:42 PM, Roedy Green wrote: > On Wed, 24 Mar 2010 15:55:30 -0700, markspace<nospam(a)nowhere.com> > wrote, quoted or indirectly quoted someone who said : > >> 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. > > I have a JTable. I get a row put it in a local variable and > synchronise on that. Does that not lock anyone else getting that > row, even if they have nothing to do with my local variable? > > AppToWatch row; > synchronized ( ALL_ROWS ) > { > row = ALL_ROWS.get( rowIndex ); > state = row.getState(); > } > ... > synchronized ( row ) > { > url = row.getVersionURL(); > marker = row.getMarker(); > } Are you sure you didn't misread IntelliJ's complaint? The thing that strikes me as odd about this code is that there are three method calls made on row's object, only two of which are synchronized on that object. It's conceivable that this is all right, but it sure looks strange to me -- and perhaps IntelliJ thinks it peculiar, too. -- Eric Sosman esosman(a)ieee-dot-org.invalid
From: Roedy Green on 25 Mar 2010 13:23 On Thu, 25 Mar 2010 00:06:56 -0400, Eric Sosman <esosman(a)ieee-dot-org.invalid> wrote, quoted or indirectly quoted someone who said : > Are you sure you didn't misread IntelliJ's complaint? all it says is "synchronization on local variable row". -- Roedy Green Canadian Mind Products http://mindprod.com If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure they stay in sync, the versions of the fact will eventually get out of sync.
From: Roedy Green on 25 Mar 2010 13:27 On Thu, 25 Mar 2010 00:06:56 -0400, Eric Sosman <esosman(a)ieee-dot-org.invalid> wrote, quoted or indirectly quoted someone who said : >> AppToWatch row; >> synchronized ( ALL_ROWS ) >> { >> row = ALL_ROWS.get( rowIndex ); >> state = row.getState(); >> } >> ... >> synchronized ( row ) >> { >> url = row.getVersionURL(); >> marker = row.getMarker(); >> } > > Are you sure you didn't misread IntelliJ's complaint? The >thing that strikes me as odd about this code is that there are >three method calls made on row's object, only two of which are >synchronized on that object. It's conceivable that this is all >right, but it sure looks strange to me -- and perhaps IntelliJ >thinks it peculiar, too. I corrected the code to read: AppToWatch row; synchronized ( ALL_ROWS ) { row = ALL_ROWS.get( rowIndex ); synchronized ( row ) { state = row.getState(); } } ... synchronized ( row ) { url = row.getVersionURL(); marker = row.getMarker(); } Now I get TWO message about synchorizing on row. -- Roedy Green Canadian Mind Products http://mindprod.com If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure they stay in sync, the versions of the fact will eventually get out of sync.
From: Roedy Green on 25 Mar 2010 13:29
On Wed, 24 Mar 2010 16:21:29 -0700, Patricia Shanahan <pats(a)acm.org> wrote, quoted or indirectly quoted someone who said : >It's difficult to know if the message was valid or not without an SSCCE. you can see the complete code at https://wush.net/websvn/mindprod/listing.php?repname=mindprod&path=/com/mindprod/vercheck/ it is a bit fat for a SSCCE. -- Roedy Green Canadian Mind Products http://mindprod.com If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure they stay in sync, the versions of the fact will eventually get out of sync. |