Class ObjectPool<DATATYPE>

  • Type Parameters:
    DATATYPE - The type of the objects contained in the pool.
    All Implemented Interfaces:
    IMutableObjectPool<DATATYPE>

    @ThreadSafe
    public final class ObjectPool<DATATYPE>
    extends Object
    implements IMutableObjectPool<DATATYPE>
    A simple generic object pool with a fixed size determined in the constructor.
    Author:
    Philip Helger
    • Constructor Detail

      • ObjectPool

        public ObjectPool​(@Nonnegative
                          int nItemCount,
                          @Nonnull
                          ISupplier<? extends DATATYPE> aFactory)
        Create a new object pool for a certain amount of items and a factory that creates the objects on demand.
        Parameters:
        nItemCount - The number of items in the pool. Must be ≥ 1.
        aFactory - The factory to create object. May not be null. The factory may not create null objects, as this leads to an error!
    • Method Detail

      • isSilentMode

        public static boolean isSilentMode()
        Returns:
        true if logging is disabled, false if it is enabled.
        Since:
        9.4.0
      • setSilentMode

        public static boolean setSilentMode​(boolean bSilentMode)
        Enable or disable certain regular log messages.
        Parameters:
        bSilentMode - true to disable logging, false to enable logging
        Returns:
        The previous value of the silent mode.
        Since:
        9.4.0
      • clearUnusedItems

        public void clearUnusedItems()