public static final class ParallelProcedure.Default<E> extends Object implements ParallelProcedure<E>
Worker threads will be created or abolished in line with the number of elements to be handled, the specified
maximum thread count and the specified thread timeout.
Thread abolishment is controled via calls of Thread.interrupt() from the thread management logic.
Also, any other Throwable thrown by the logic Consumer will cause the throwing worker thread
to be abolished as well and the logic instance to be disposed.
Locking is done via the instance itself. There are opinions that say it is preferable to do locking via a dedicated internal unshared locking object to prevent "lock stealing" from outside. However, obtaining the particular lock in an outside context can also be desired or even needed. E.g.: synchronize on the procedure instance itself in the calling context, apply the procedure to all elements in a collection and then release the lock (leave the synchronized block) to start all worker threads as soon all the collection's elements have been collected. It is probably due to requirements like this that lock hiding strategies get extended by means to publicly present their hidden lock instance. But then that defeats the purpose of lock hiding altogether and yields the direct and simpler syntactical way of using this-synchronized internal methods the superior one. In the end, synchronizing/locking on the instance itself is fine. It just may not be messed up. As with anything else in writing code.
ParallelProcedure.Default<E>, ParallelProcedure.LogicProvider<S,P extends Consumer<? super S>>, ParallelProcedure.ThreadCountProvider, ParallelProcedure.ThreadTimeoutProvider| Constructor and Description |
|---|
Default(ParallelProcedure.LogicProvider<? super E,? extends Consumer<? super E>> logicProvider,
int threadCount) |
Default(ParallelProcedure.LogicProvider<? super E,? extends Consumer<? super E>> logicProvider,
int threadCount,
int threadTimeout) |
Default(ParallelProcedure.LogicProvider<? super E,? extends Consumer<? super E>> logicProvider,
ParallelProcedure.ThreadCountProvider threadCountProvider)
Alias for
Default(logicProvider, maxThreadCount, 1000). |
Default(ParallelProcedure.LogicProvider<? super E,? extends Consumer<? super E>> logicProvider,
ParallelProcedure.ThreadCountProvider threadCountProvider,
ParallelProcedure.ThreadTimeoutProvider threadTimeout)
Validetes the passed parameters but does neither create threads nor call any of the logic provider's methods.
|
| Modifier and Type | Method and Description |
|---|---|
void |
accept(E element)
Applies a wrapped logic by delegating its execution to another thread.
|
int |
currentThreadCount() |
public Default(ParallelProcedure.LogicProvider<? super E,? extends Consumer<? super E>> logicProvider, int threadCount)
public Default(ParallelProcedure.LogicProvider<? super E,? extends Consumer<? super E>> logicProvider, int threadCount, int threadTimeout)
public Default(ParallelProcedure.LogicProvider<? super E,? extends Consumer<? super E>> logicProvider, ParallelProcedure.ThreadCountProvider threadCountProvider)
Default(logicProvider, maxThreadCount, 1000).logicProvider - the instance that provides the logic instances to be used by the worker threads.threadCountProvider - the maximum number of concurrent threads to be created by this instance.public Default(ParallelProcedure.LogicProvider<? super E,? extends Consumer<? super E>> logicProvider, ParallelProcedure.ThreadCountProvider threadCountProvider, ParallelProcedure.ThreadTimeoutProvider threadTimeout)
Valied arguments are:
logicProvider - the instance that provides the logic instances to be used by the worker threads.threadCountProvider - the maximum number of concurrent threads to be created by this instance.threadTimeout - the thread abolishment timeout in milliseconds.public int currentThreadCount()
public final void accept(E element)
ParallelProcedureCopyright © 2022 MicroStream Software. All rights reserved.