Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

Synchronization and Locks
now we are discussing about syncronisaiton works with licks.in the java programming language every object have a built in lock.its only we use when object has a syncronised code. until they have only 1 lock per object.if at a tym one thread pick the lock then that tym no other thread sncronised the lock.At that point, the lock is free until some other thread enters a synchronized method on that object.
              We need to remember the following key points about locking and synchronization : 
> Only methods can be synchronized, not variables.
> Each object has just one lock.
> Not all methods in a class must be synchronized. A class can have both synchronized
and nonsynchronized methods.
> If two methods are synchronized in a class, only one thread can be accessing one of the two methods. In other words, once a thread acquires the lock on an object, no other thread can enter any of the synchronized methods in that class.
> If a thread goes to sleep, it takes its locks with it.
> A thread can acquire more than one lock.
> We can synchronize a block of code rather than a method.
Posted By: Name:Rajesh Kr URL: Synchronization and Locks