1 package org.columba.core.base; 17 18 public class Mutex { 19 private boolean mutex; 20 21 public Mutex() { 22 mutex = false; 23 } 24 25 29 public synchronized void lock() { 30 while (mutex) { 31 try { 32 wait(); 33 } catch (InterruptedException e) { 34 if (Thread.currentThread().isInterrupted()) { 35 throw new RuntimeException (e); 37 } 38 39 } 41 } 42 43 mutex = true; 44 } 45 46 public synchronized void release() { 47 mutex = false; 48 notify(); 49 } 50 } 51 | Popular Tags |