Sure, its possible. If you call another synchornized method in the same class (object) then it has the lock and it continues with the new method. If you call a synchronized method in another object, then it needs to aquire THAT lock as well... until it doesnt i guess it is STUCK in the first synchronized method (which can cause a pretty nasty deadlock).
Yes. Calling an unsynchronized method from a synchronized one is like copying the body of the unsynchronized method into the synchronized method. HTH, M
Max, ... but other threads trying to access the unsynchronized method will be allowed access correct? therefore it isn't truly like copying the unsynchronized method into the synchronized one? Kevin
Originally posted by Snigdha Solanki: What will happen if you call an unsynchronized method inside a synchrnized method? Will that method be automatically synchronized?
No. only the synchronized method will be synchronized all Threads will be allowed into the first method, but they will all block upon trying to enter the synchronized method and just 1 will let thru.
No. only the synchronized method will be synchronized QUOTE] CL is correct. _IF_ you call an unsynchronized from and synchronized method, _THEN_ it's like copying the body of the unsynchronized method in: Otherwise, you're just calling an unsynchronized method.
Hmm. Reverting back to when I didn't know about threads maybe I should expound. If you call an unsychronized method from inside a synchronized method, you don't "loose" your synchronization. Your are technically inside of a synchronized method and the lock will not be released until you leave the outer synchronized method.
Exactly. On a related note, if you call one synchronized method from another synchronized method, then you actually achieve(and release) two locks on the Object in question(usually the this Object) before all is said and done. HTH, M [ July 12, 2002: Message edited by: Max Habibi ]