java.lang.Object
net.i2p.addressbook.HostChecker.DynamicSemaphore
- Enclosing class:
HostChecker
Semaphore whose permit limit can change at runtime, so concurrency adjustments apply to a cycle already in progress. Raising the limit wakes blocked acquirers; lowering it only affects future acquisitions, never in-flight ones.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ObjectLock guarding the permit counts.private intPermits allowed after a resize.private intPermits currently available.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescription(package private) voidacquire()Block until below the concurrent limit, then count one more acquisition.(package private) voidrelease()Release one acquisition and wake a blocked acquirer.(package private) voidsetMaxPermits(int maxPermits) Raise or lower the concurrent acquisition limit.
Field Details
_lock
Lock guarding the permit counts._permits
private int _permitsPermits currently available._maxPermits
private volatile int _maxPermitsPermits allowed after a resize.
Constructor Details
DynamicSemaphore
DynamicSemaphore(int maxPermits) Creates a semaphore that can be resized.- Parameters:
maxPermits- the initial permit limit
Method Details
setMaxPermits
void setMaxPermits(int maxPermits) Raise or lower the concurrent acquisition limit.- Parameters:
maxPermits- the new limit
acquire
Block until below the concurrent limit, then count one more acquisition.- Throws:
InterruptedException- if the calling thread is interrupted while waiting for a permit
release
void release()Release one acquisition and wake a blocked acquirer.