1 package org.jboss.cache.lock; 2 3 import java.util.concurrent.Semaphore ; 4 import java.util.concurrent.TimeUnit ; 5 import java.util.concurrent.locks.Condition ; 6 import java.util.concurrent.locks.Lock ; 7 8 11 public class SemaphoreLock extends Semaphore implements Lock 12 { 13 14 17 private static final long serialVersionUID = -15293253129957476L; 18 19 public SemaphoreLock(int permits) 20 { 21 super(permits); 22 } 23 24 public void lock() 25 { 26 try 27 { 28 acquire(); 29 } 30 catch (InterruptedException e) 31 { 32 lock(); } 34 } 35 36 public void lockInterruptibly() throws InterruptedException 37 { 38 acquire(); 39 } 40 41 public Condition newCondition() 42 { 43 throw new UnsupportedOperationException (); 44 } 45 46 public boolean tryLock() 47 { 48 return tryAcquire(); 49 } 50 51 public boolean tryLock(long arg0, TimeUnit arg1) throws InterruptedException 52 { 53 return tryAcquire(arg0, arg1); 54 } 55 56 public void unlock() 57 { 58 release(); 59 } 60 61 } 62 | Popular Tags |