5 |
|
*/ |
6 |
|
|
7 |
|
package java.util.concurrent; |
8 |
+ |
import java.util.concurrent.locks.*; |
9 |
|
|
10 |
|
/** |
11 |
|
* A semaphore guaranteeing that threads invoking any of the {@link |
31 |
|
public class FairSemaphore extends Semaphore { |
32 |
|
|
33 |
|
/* |
34 |
< |
* This differs from Semaphore only in that it uses a |
35 |
< |
* FairReentrantLock. Because the FairReentrantLock guarantees |
36 |
< |
* FIFO queuing, we don't need to do anything fancy to prevent |
34 |
> |
* This differs from Semaphore only in that it uses a Fair |
35 |
> |
* ReentrantLock. Because the Fair ReentrantLock guarantees FIFO |
36 |
> |
* queuing, we don't need to do anything fancy to prevent |
37 |
|
* overtaking etc. for the multiple-permit methods. The only |
38 |
|
* minor downside is that multi-permit acquires will sometimes |
39 |
|
* repeatedly wake up finding that they must re-wait. A custom |
47 |
|
* @param permits the initial number of permits available |
48 |
|
*/ |
49 |
|
public FairSemaphore(long permits) { |
50 |
< |
super(permits, new FairReentrantLock()); |
50 |
> |
super(permits, new ReentrantLock(true)); |
51 |
|
} |
52 |
|
|
53 |
|
/** |