Mercurial Hosting > luan
comparison src/goodjava/lucene/logging/SemaphoreLock.java @ 1538:634f6765830e
use goodjava/lucene/logging
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 07 Aug 2020 21:42:16 -0600 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1537:f7649ad6e3e7 | 1538:634f6765830e |
|---|---|
| 1 package goodjava.lucene.logging; | |
| 2 | |
| 3 import java.util.concurrent.Semaphore; | |
| 4 import java.util.concurrent.TimeUnit; | |
| 5 | |
| 6 | |
| 7 public final class SemaphoreLock { | |
| 8 private final Semaphore semaphore = new Semaphore(1); | |
| 9 | |
| 10 public void unlock() { | |
| 11 semaphore.release(); | |
| 12 } | |
| 13 | |
| 14 public boolean isLocked() { | |
| 15 return semaphore.availablePermits() == 0; | |
| 16 } | |
| 17 | |
| 18 public boolean tryLock(long time,TimeUnit unit) throws InterruptedException { | |
| 19 return semaphore.tryAcquire(time,unit); | |
| 20 } | |
| 21 } |
