Hi there,
In K&B, Ch.9, page 736, it says:
If a class has both synchronized and non-synchronized methods, multiple threads can still access the class's non-synchronized methods!
I wasn't sure whether that meant that you can still access the unsynchronized methods even if another
thread has the object's lock. I wrote the following code to find out:
The out put I get is:
I'm taking this to mean that:
1. The Thread called 'one' starts the run method and enters the synchronized block where it aquires the lock to the LockTest instance.
2. It executes the for loop until i == 100 and then sleeps. *But it still has the lock*
3. Because the Thread one is sleeping, and dispite the fact that Thread one has the lock, the 'main' thread can still access the *unsynchronized* printStuff() method of the LockThis instance, so it is allowed to execute the for loop in the main method.
4. Thread one wakes up and finishes executing the run() method and releases the lock on the LockTest object.
Does everyone else agree that this is what is happening?
Cheers
Joe