8/06/2004

is synchronization not enough?

java5 has a class called Lock, with methods lock() and unlock(). They can be used to lock in one block and unlock in another block (even in different methods, but needs to be explicitly unlocked unlike synchronized). Lock is termed as an enhancement to synchronization

Now we can write code like
Lock a = ...;
Lock b = ...;
{
a.lock();
}
...;
b.lock();
...;
a.unlock(); // reversing the order.
{
b.unlock();
}

Where to use these, I am waiting for a execuse :)

0 Comments:

Post a Comment

<< Home