Class ConcurrentCachedGenerator<T>
java.lang.Object
dev.nm.stat.random.rng.concurrent.cache.ConcurrentCachedGenerator<T>
- Type Parameters:
T
- the type of the item
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Defines a generic generator of typeT
. -
Constructor Summary
ConstructorsConstructorDescriptionConcurrentCachedGenerator
(ConcurrentCachedGenerator.Generator<T> generator, int cacheSize) Creates a new instance which wraps the given item generator and uses a cache of the specified size. -
Method Summary
-
Constructor Details
-
ConcurrentCachedGenerator
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 generatorcacheSize
- the size of the cache
-
-
Method Details
-
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.
-