Lock.java 422 B

1234567891011121314151617181920212223242526
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. /**
  6. *
  7. * @author LH
  8. */
  9. public class Lock{
  10. private boolean isLocked = false;
  11. public synchronized void lock()
  12. throws InterruptedException{
  13. while(isLocked){
  14. wait();
  15. }
  16. isLocked = true;
  17. }
  18. public synchronized void unlock(){
  19. isLocked = false;
  20. notify();
  21. }
  22. }