Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread synch and inner classes

 
tom walters
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a class with 2 inner classes that are threads

how do i make this thread safe? make the check() method in Checker synchronized? put the o = c.check(); in a synchronized block using the monitor String object?
[ April 26, 2002: Message edited by: tom walters ]
Formatted and added code tags - George
[ May 28, 2002: Message edited by: George Brown ]
 
Thomas Smets
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tom,
I simplified your code as the stub you gave would never be able to compile :
Please note that I don't like the idea that the []inotification[/i] has to be in a synchronized block, but it's rather logical to have it so... So !
Please also note that this example s inspired from "JAVA threads" by Scott Oaks & Henry Wong at O'Reilly, ISBN 1-56592-216-6
Make sure you get the second edition at least, while these references dates to the first edition (ISBN number)


Rgds,
Thomas,
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom, either of your proposed solutions would make that a thread safe operation.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by CL Gilbert:
Tom, either of your proposed solutions would make that a thread safe operation.

Mhhh, you probably meant to write neither?
It's not the check() that is critical, but parallel usage of o. This usage has to be synchronized.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:

Mhhh, you probably meant to write neither?
It's not the check() that is critical, but parallel usage of o. This usage has to be synchronized.

Since the threads are not sharing anything, their are no synchronization issues.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic