Package ej.sni

Class PoolOfReusableResources

    • Constructor Detail

      • PoolOfReusableResources

        public PoolOfReusableResources​(int maxNbResources)
        Allocate a new pool of resources
        Parameters:
        maxNbResources - a strictly positive integer giving the maximum number of allocated resources, or 0 if an unlimited number of resources is allowed
    • Method Detail

      • reserve

        public Object reserve()
        Reserve a buffer. In case all resources are in use and the maximum number of resources is not reached, a new buffer is allocated. Otherwise this function blocks until a buffer is available
        Returns:
        an array
      • release

        public void release​(Object buffer)
      • newResource

        protected abstract Object newResource()
        Allocate a new resource
        Returns:
        the new allocated resource