Issue #1861 - Limit total bytes pooled by ByteBufferPools.
Small improvement after review. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
676b7ecaba
commit
de0c8e3531
|
@ -153,19 +153,18 @@ public class ArrayByteBufferPool extends AbstractByteBufferPool
|
|||
|
||||
private void clearOldestBucket(boolean direct)
|
||||
{
|
||||
long oldest = 0;
|
||||
long oldest = Long.MAX_VALUE;
|
||||
int index = -1;
|
||||
Bucket[] buckets = bucketsFor(direct);
|
||||
long now = System.nanoTime();
|
||||
for (int i = 0; i < buckets.length; ++i)
|
||||
{
|
||||
Bucket bucket = buckets[i];
|
||||
if (bucket == null)
|
||||
continue;
|
||||
long age = now - bucket.getLastUpdate();
|
||||
if (age > oldest)
|
||||
long lastUpdate = bucket.getLastUpdate();
|
||||
if (lastUpdate < oldest)
|
||||
{
|
||||
oldest = age;
|
||||
oldest = lastUpdate;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ public interface ByteBufferPool
|
|||
private final int _capacity;
|
||||
private final int _maxSize;
|
||||
private final AtomicInteger _size;
|
||||
private long _lastUpdate;
|
||||
private long _lastUpdate = System.nanoTime();
|
||||
|
||||
public Bucket(ByteBufferPool pool, int capacity, int maxSize)
|
||||
{
|
||||
|
|
|
@ -150,17 +150,16 @@ public class MappedByteBufferPool extends AbstractByteBufferPool
|
|||
|
||||
private void clearOldestBucket(boolean direct)
|
||||
{
|
||||
long oldest = 0;
|
||||
long oldest = Long.MAX_VALUE;
|
||||
int index = -1;
|
||||
ConcurrentMap<Integer, Bucket> buckets = bucketsFor(direct);
|
||||
long now = System.nanoTime();
|
||||
for (Map.Entry<Integer, Bucket> entry : buckets.entrySet())
|
||||
{
|
||||
Bucket bucket = entry.getValue();
|
||||
long age = now - bucket.getLastUpdate();
|
||||
if (age > oldest)
|
||||
long lastUpdate = bucket.getLastUpdate();
|
||||
if (lastUpdate < oldest)
|
||||
{
|
||||
oldest = age;
|
||||
oldest = lastUpdate;
|
||||
index = entry.getKey();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue