Skip to content

Instantly share code, notes, and snippets.

@fmerlin
Last active January 16, 2017 09:38
Show Gist options
  • Save fmerlin/6ed37b6ae2271297298d3943772dc942 to your computer and use it in GitHub Desktop.
Save fmerlin/6ed37b6ae2271297298d3943772dc942 to your computer and use it in GitHub Desktop.
to use a lock in a try catch block
import java.util.concurrent.locks.Lock;
/**
* to use a lock in a try catch block
*/
public class AutoLock implements AutoCloseable {
final Lock ref;
public AutoLock(Lock lock) {
ref = lock;
ref.lock();
}
@Override
public void close() {
ref.unlock();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment