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 ]
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)
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.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus