Mercurial Hosting > luan
annotate src/goodjava/lucene/logging/SemaphoreLock.java @ 1677:ea7075b7afe1
switch to index.json
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 31 May 2022 14:36:16 -0600 |
parents | 634f6765830e |
children |
rev | line source |
---|---|
1538
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 package goodjava.lucene.logging; |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 import java.util.concurrent.Semaphore; |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 import java.util.concurrent.TimeUnit; |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 public final class SemaphoreLock { |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 private final Semaphore semaphore = new Semaphore(1); |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 public void unlock() { |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 semaphore.release(); |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 } |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 public boolean isLocked() { |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 return semaphore.availablePermits() == 0; |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 } |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 public boolean tryLock(long time,TimeUnit unit) throws InterruptedException { |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 return semaphore.tryAcquire(time,unit); |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 } |
634f6765830e
use goodjava/lucene/logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 } |