Please: try-with-resouces Lock support!
Neal Gafter
neal at gafter.com
Wed Feb 23 12:45:09 PST 2011
If I recall, Doug Lea's comment was that the overhead of creating a
new object every time you lock negates much of the performance
benefits of the underlying primitives, and the authors of the original
proposal rejected this as a valid use case for the new language
feature.
On Wednesday, February 23, 2011, Gernot Neppert <mcnepp02 at googlemail.com> wrote:
> 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