All:
Consider this code:
A given run of this code can produce the results "11a 10a 11b 10b".
OK. I understand that the locked() method is synchronized so that only one
thread at a time can use it. I also see that the run() method is NOT synchronized. I don't understand how this result is possible because while the run() method is NOT synchronized the locked() method is. So lets see, one of the threads starts and gets into the run() method first and then invokes the locked() method, thereby getting the lock on the object. That is supposed to prevent the other thread from executing the same method at the same time, correct? Which is what we want because both threads are using the same runnable. But, obviously that is not happening here. Could the JVM be swapping out the two threads and that's why I am getting this kind of result occasionally? If not, please help me understand how this result occurs.
Thanks to all for your time and consultation.
Gary