neethi,for the reason the threads are not predictable java has imposed synchronized in the compile time itself by providing this as one of the access specifier..synchronization basically lock that instance of the object.if the method is syn...ed before it is invoked by an thread the methods aquires the lock of the object and because the lock is not available for the other syn...ed methods,it will not start executing..
There is only one synchronization construct in Java and that is a lock/Monitor pair. A block(peice of code) or a set of blocks that need to be synchronized should be associated with a lock_object. Every thread that needs to execute that block (critical section) needs to acquire a monitor over the lock_object. Whoever gets the monitor on the lock executes. The others wait for it to release the lock. You can 1) Acquire a lock/monitor on the whole Object 2) Acquire a lock on a part of the code within a method of the object 3) Acquire a lock/monitor on the Class (for static members) Other than that there are no mutex/semaphores/...etc. kind of synchronization constructs. But the above takes care of almost all types of requirements. Jigs @(www.enthuware.com)
2) Acquire a lock on a part of the code within a method of the object
Code does not have a lock which can be acquired. I guess you mean that aquire a lock on a specific object (it can be or not be the instance object which owns the code) to lock the code block. Thanks! Roseanne Join our Study Group when certified