View Single Post
Old 11-06-2012, 05:24 PM   PM User | #3
Zaid
New Coder

 
Join Date: Sep 2012
Location: Mumbai
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Zaid is an unknown quantity at this point
Thumbs up

Quote:
Originally Posted by Fou-Lu View Post
a1 and a2 are running through b1 and b2. These are threads of their own, so you are not doing anything to block the other objects, so issuing a sleep on that running thread won't impact another thread. There are many ways to do this from the simple implicit locks of the object, to running with ExecutorService and pools or writing your own threads and runnables. But you'll need to write the blocking conditions for the thread.
I think u got it wrong...My question was that if a synchronized method is called by a thread then it should not allow its control to other threads until it releases control for the 1st thread....
I guess when a synchronized method is called by the same reference for the 2nd time then it serializes it(blocks it until the first call returns control)...In the above case, I have used different references(a1 and a2) and although they call the same method they are allow concurrent access without synchronization. Correct if I am wrong
Zaid is offline   Reply With Quote