I hope you might be in a position to help me. As I was studying threads on Bruce Eckel's thinking in java, I came across the synchronized statement.
the following was taken from Java Specs: "Acquiring the lock associated with an object does not of itself prevent other threads from accessing fields of the object or invoking unsynchronized methods on the object. Other threads can also use synchronized methods or the synchronized statement in a conventional manner to achieve mutual exclusion."
Now, if a method (object B) declares within itself a synchronized statement referencing some other object A , and within the statement calling some methods not synchronized belonging to A, what happens? I mean, what are the monitor regions guarded by the synchronized statement? Isn't it error prone?
I should like to thank you in advance for your help luka
As you can see, even if a thread has aquired a lock on an object, you can do anything you want with that object in other threads as long as you don't try to aquire its lock.
In the end, is up to you to synchronize you code in order to have a bug free code.