This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
If we have 2 synchronized methods in a class. One thread is accesing first synchronized method. Will another thread be allowed to access the second synchronized method? How will the monitor state/locks will be managed? ------------------ Shailendra Bade Mumbai, India Mail to: bades@vsnl.com
Shailendra Bade<BR>Mumbai, India<BR>Mail to: bades@vsnl.com
David Harrigan
Ranch Hand
Joined: Dec 12, 2000
Posts: 52
posted
0
No. Once a thread enters a synchronized block (method or whatever) then that thread "owns" that entire object until the lock is released. No other thread will be able to access the syncrhonized methods in that object, unless the synchronized block calls a wait(). David.
Jerry Pulley
Ranch Hand
Joined: Sep 19, 2000
Posts: 221
posted
0
David, Just to clarify, your response is correct in the case of two <code>synchronized</code> methods but not necessarily in the cases of one sync'ed method and one sync'ed statement, or two sync'ed statements. If the two critical sections are sync'ed on different monitor objects, then they are not mutually exclusive.<pre> class A { public synchronized void A() { ... } public void B() { synchronized (someOtherObject) { ... } } }</pre> Separate threads may execute simultaneously in A() and B(). Jerry