public void run() { // Expire unused buffers every seconds while (!timeToStop) { try { Thread.sleep(1000); } catch (InterruptedException e) { //ignore } // Check if expiration is disabled. long timeout = getTimeoutMillis(); if (timeout <= 0L) { continue; } // Expire old buffers long expirationTime = System.currentTimeMillis() - timeout; for (int i = directBufferStacks.length - 1; i >= 0; i--) { ExpiringStack stack = directBufferStacks[i]; synchronized (stack) { stack.expireBefore(expirationTime); } } for (int i = heapBufferStacks.length - 1; i >= 0; i--) { ExpiringStack stack = heapBufferStacks[i]; synchronized (stack) { stack.expireBefore(expirationTime); } } } } }