public class WorkSync<Material,W extends Work<Material,W>> extends Object
The technique used here is inspired in part both by the Flat Combining concept from Hendler, Incze, Shavit & Tzafrir, and in part by the wait-free linked queue design by Vyukov.
In a sense, this turns many small, presumably concurrent, pieces of work into fewer, larger batches of work, that is then applied to the material under synchronisation.
Obviously this only makes sense for work that a) can be combined, and b) where the performance improvements from batching effects is large enough to overcome the overhead of collecting and batching up the work units.
Work| Constructor and Description |
|---|
WorkSync(Material material)
Create a new WorkSync that will synchronize the application of work to
the given material.
|
| Modifier and Type | Method and Description |
|---|---|
void |
apply(W work)
Apply the given work to the material in a thread-safe way, possibly by
combining it with other work.
|
AsyncApply |
applyAsync(W work)
Apply the given work to the material in a thread-safe way, possibly asynchronously if contention is observed
with other threads, and possibly by combining it with other work.
|
public WorkSync(Material material)
material - The material we want to apply work to, in a thread-safe
way.public void apply(W work) throws ExecutionException
work - The work to be done.ExecutionException - if this thread ends up performing the piled up work,
and any work unit in the pile throws an exception. Thus the current thread is not
guaranteed to observe any exception its unit of work might throw, since the
exception will be thrown in whichever thread that ends up actually performing the work.public AsyncApply applyAsync(W work)
The work will be applied immediately, if no other thread is contending for the material. Otherwise, the work
will be enqueued for later application, which may occur on the next call to apply(Work) on this
WorkSync, or the next call to AsyncApply.await() from an AsyncApply instance created
from this WorkSync. These calls, and thus the application of the enqueued work, may occur in an
arbitrary thread.
The returned AsyncApply instance is not thread-safe. If so desired, its ownership can be transferred to
other threads, but only in a way that ensures safe publication.
If the given work causes an exception to be thrown, then that exception will only be observed by the thread that
ultimately applies the work. Thus, exceptions caused by this work are not guaranteed to be associated with, or
made visible via, the returned AsyncApply instance.
work - The work to be done.AsyncApply instance representing the enqueued - and possibly completed - work.Copyright © 2002–2017 The Neo4j Graph Database Project. All rights reserved.