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

com.fluxtion.runtime.util.ObjectPool Maven / Gradle / Ivy

There is a newer version: 9.7.4
Show newest version
package com.fluxtion.runtime.util;

import com.fluxtion.runtime.partition.LambdaReflection.SerializableSupplier;

import java.util.ArrayList;
import java.util.List;

public class ObjectPool {

    private final SerializableSupplier supplier;
    private transient final List freeList = new ArrayList<>();

    public ObjectPool(SerializableSupplier supplier) {
        this.supplier = supplier;
    }

    public T checkOut() {
        if (freeList.isEmpty()) {
            return supplier.get();
        }
        return freeList.remove(freeList.size() - 1);
    }

    public void checkIn(T returnedInstance) {
        freeList.add(returnedInstance);
    }

    public void reset() {
        freeList.clear();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy