Mercurial Hosting > luan
annotate src/goodjava/lucene/logging/SemaphoreLock.java @ 1758:27a2530f04b6
fix reload nginx from startup script
author | Vadim Filimonov <fffilimonov@yandex.ru> |
---|---|
date | Mon, 20 Feb 2023 09:02:20 +0200 |
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 } |