Class ConcurrentCachedGenerator<T>

  • Type Parameters:
    T - the type of the item
    All Implemented Interfaces:
    Seedable

    public class ConcurrentCachedGenerator<T>
    extends Object
    implements Seedable
    A generic wrapper that makes an underlying item generator thread-safe by caching generated items in a concurrently-accessible list. This is more efficient than plainly synchronizing all accessors of the generator.
    • Constructor Detail

      • ConcurrentCachedGenerator

        public ConcurrentCachedGenerator​(ConcurrentCachedGenerator.Generator<T> generator,
                                         int cacheSize)
        Creates a new instance which wraps the given item generator and uses a cache of the specified size. A larger cache will make the concurrency slightly faster at the expense of increased memory usage, but may lead to the computation of unnecessary values at the tail.
        Parameters:
        generator - the underlying generator
        cacheSize - the size of the cache
    • Method Detail

      • next

        public T next()
        Returns the next value in the generated sequence.
        Returns:
        the next generated value
      • seed

        public void seed​(long... seeds)
        Description copied from interface: Seedable
        Seed the random number/vector/scenario generator to produce repeatable experiments.
        Specified by:
        seed in interface Seedable
        Parameters:
        seeds - the seeds