/** * Removes overflow. If <code>forPut</code> is <code>true</code>, then * this uses <code>size() + 1</code> when computing size. */ protected void removeOverflow(boolean forPut) { int sizeToCompareTo = forPut ? maxSize - 1 : maxSize; while (size() > sizeToCompareTo) { Entry entry = removeRandom(); // if removeRandom() returns null, break out of the loop. Of course, // since we're not locking, the size might not actually be null // when we do this. But this prevents weird race conditions from // putting this thread into more loops. if (entry == null) break; overflowRemoved(entry.getKey(), entry.getValue()); } }
/** * Removes overflow. If <code>forPut</code> is <code>true</code>, then * this uses <code>size() + 1</code> when computing size. */ protected void removeOverflow(boolean forPut) { int sizeToCompareTo = forPut ? maxSize - 1 : maxSize; while (size() > sizeToCompareTo) { Entry entry = removeRandom(); // if removeRandom() returns null, break out of the loop. Of course, // since we're not locking, the size might not actually be null // when we do this. But this prevents weird race conditions from // putting this thread into more loops. if (entry == null) break; overflowRemoved(entry.getKey(), entry.getValue()); } }