................................................
while ((avail = unused.size()) == 0)
{
// the if case below can only occur when 1) a user attempts a
// checkout which would provoke an acquire; 2) this
// increments the pending acquires, so we go to the
// wait below without provoking postAcquireMore(); 3)
// the resources are acquired; 4) external management
// of the pool (via for instance unpoolResource()
// depletes the newly acquired resources before we
// regain this' monitor; 5) we fall into wait() with
// no acquires being scheduled, and perhaps a managed.size()
// of zero, leading to deadlock. This could only occur in
// fairly pathological situations where the pool is being
// externally forced to a very low (even zero) size, but
// since I've seen it, I've fixed it.
if (pending_acquires == 0 && managed.size() < max)
_recheckResizePool();
this.wait(timeout);
if (timeout > 0 && System.currentTimeMillis() - start > timeout)
throw new TimeoutException("A client timed out while waiting to acquire a resource from " + this + " -- timeout at awaitAvailable()");
if (force_kill_acquires)
throw new CannotAcquireResourceException("A ResourcePool could not acquire a resource from its primary factory or source.", getLastAcquisitionFailure());
ensureNotBroken();
}
...................................