Class ConcurrentCachedGenerator<T>

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

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 Details

    • 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.
      generator - the underlying generator
      cacheSize - the size of the cache
  • Method Details

    • next

      public T next()
      Returns the next value in the generated sequence.
      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
      seeds - the seeds