19 |
|
* <p>Semaphores are often used to restrict the number of threads than can |
20 |
|
* access some (physical or logical) resource. For example, here is |
21 |
|
* a class that uses a semaphore to control access to a pool of items: |
22 |
< |
* <pre> |
22 |
> |
* <pre> {@code |
23 |
|
* class Pool { |
24 |
|
* private static final int MAX_AVAILABLE = 100; |
25 |
|
* private final Semaphore available = new Semaphore(MAX_AVAILABLE, true); |
61 |
|
* } |
62 |
|
* return false; |
63 |
|
* } |
64 |
< |
* |
65 |
< |
* } |
66 |
< |
* </pre> |
64 |
> |
* }}</pre> |
65 |
|
* |
66 |
|
* <p>Before obtaining an item each thread must acquire a permit from |
67 |
|
* the semaphore, guaranteeing that an item is available for use. When |