All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.refinitiv.eta.json.util.ObjectPool Maven / Gradle / Ivy

The newest version!
/*|-----------------------------------------------------------------------------
 *|            This source code is provided under the Apache 2.0 license
 *|  and is provided AS IS with no warranty or guarantee of fit for purpose.
 *|                See the project's LICENSE.md for details.
 *|           Copyright (C) 2019-2022 LSEG. All rights reserved.     
 *|-----------------------------------------------------------------------------
 */

package com.refinitiv.eta.json.util;

import java.util.function.Supplier;

public class ObjectPool {
    final UtilQueue pool;
    final static int DEFAULT_INITIAL_SIZE = 16;

    public ObjectPool(boolean isConcurrent, Supplier supplier) {
        this(isConcurrent, DEFAULT_INITIAL_SIZE, supplier);
    }

    public ObjectPool(boolean isConcurrent, int initialSize, Supplier supplier) {
        if (isConcurrent)
            pool = new UtilQueueConcurrent(initialSize, supplier);
        else {
            pool = new UtilQueue(initialSize, supplier);
        }
    }

    public T get() {
        return pool.get();
    }

    public void release(T obj) {
        pool.add(obj);
    }

    public void growPool(int numOfObjects) {
        pool.growPool(numOfObjects);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy