com.fluxtion.runtime.util.ObjectPool Maven / Gradle / Ivy
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