Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework drainLoop so that extra pending acquires are better culled (#122)
This commit reworks the whole SimpleDequePool#drainLoop and adds some WIP-protected logic to `pendingOffer`. By evaluating the `PENDING_COUNT` and queue size behind the guard of the WIP, we're better at catching the pending borrowers that should be failed fast due to going over the `maxPending` limit, while reliably taking into account the available permits (and the borrowers that have effectively been served via newly permitted allocations). The `AbstractPool.PENDING_COUNT` field is now incremented immediately upon `pendingOffer`, but is decremented back if the `pendingOffer` can win the WIP and start a simplified drain loop in which we detect that a resource is or will be available for that pending. This refactor also ensures that `drain` is called only once in the scenario where N allocations take place (warm up case). Finally, the increased robustness of the solution is covered by a stress test using JCStress. Fixes #121.
- Loading branch information