Last active
January 16, 2017 09:38
-
-
Save fmerlin/6ed37b6ae2271297298d3943772dc942 to your computer and use it in GitHub Desktop.
to use a lock in a try catch block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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