Please: try-with-resouces Lock support!
Gernot Neppert
mcnepp02 at googlemail.com
Wed Feb 23 09:31:53 PST 2011
Hi all,
this has been discussed here before, but somehow got lost:
Wouldn't it be very handy having a class
"java.util.concurrent.AutoLockable" that could be used as follows:
try(AutoLockable locked = AutoLockable.locked(lock))
{
// Do something in locked scope
}
It would look something like this:
package java.util.concurrent.locks;
public abstract class AutoLockable implements AutoCloseable {
public static AutoLockable locked(final Lock lock)
{
lock.lock();
return new AutoLockable() {
@Override
public void close() {
lock.unlock();
}
};
}
public abstract void close();
}
More information about the coin-dev
mailing list