Created
August 13, 2015 13:42
-
-
Save ivanursul/cf75f37feb51fc54e3a7 to your computer and use it in GitHub Desktop.
Lock.java for www.ivanursul.com
This file contains hidden or 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
| public class Lock{ | |
| private boolean isLocked = false; | |
| public synchronized void lock() | |
| throws InterruptedException{ | |
| while(isLocked){ | |
| wait(); | |
| } | |
| isLocked = true; | |
| } | |
| public synchronized void unlock(){ | |
| isLocked = false; | |
| notify(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment