odnoklassniki/one-nio

Pool checker unhappy: borrowObject() and returnObject() in Pool only operate the first object

forchid opened this issue · 2 comments

In the one.nio.pool.Pool, the object allocation and deallocation only occurs in the head of the pool. This way or strategy leads to other objects can't be checked in a pool heartbeat checker of application:

 public final T borrowObject() throws PoolException, InterruptedException {
        synchronized (this) {
            for (long timeLimit = 0; ; ) {
                // First try to get an idle object from the queue
                T object = pollFirst();
                if (object != null) {
                    return object;
                }
    public final void returnObject(T object) {
        synchronized (this) {
            if (!closed) {
                if (waitingThreads > 0) notify();
                addFirst(object); // Using addLast() for pool checker friendly
                return;
            }
        }
        destroyObject(object);
    }

Suggest that Using addLast() instead of addFirst() in Pool.returnObject(), and no performance loss in LinkedList.

This is the intended behavior.
In the past I benchmarked both stratagies, and LIFO appears to perform slightly better while keeping the smaller number of active objects.

I could probably add an option to choose between FIFO/LIFO, but the defaults are not going to change anyway.

Added Pool.fifo and fifo ConnectionString option.
6604ab2