Message-ID: <381606320.167.1409151740338.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_166_1867938659.1409151740337" ------=_Part_166_1867938659.1409151740337 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Dataflow concurrency offers an alternative concurrency model, wh= ich is inherently safe and robust.
Check out the small example written in Groovy using GPars, which sums re= sults of calculations performed by three concurrently run tasks:
We start three logical tasks, which can run in parallel and perform thei= r particular activities. The tasks need to exchange data and they do so usi= ng Dataflow Variables. Think of Dataflow Variables as one-= shot channels safely and reliably tranferring data from producers to their = consumers.
The Dataflow Variables have a pretty straightforward semantics. When a t= ask needs to read a value from DataflowVariable(through the val pr= operty), it will block until the value has been set by another taks or thre= ad (using the '<<' operator). Each DataflowVariable can be s= et only oncein its lifetime. Notice that you don't have to= bother with ordering and synchronizing the tasks or threads and their acce= ss to shared variables. The values are magically transferred among tasks at= the right time without your intervention. The data flow seamlessly among t= asks / threads without your intervention or care.
Implementation detail: The three tasks in the example <= strong>do not necessarily need to be mapped to three physical threads. Tasks represent so-called "green" or "logical" thr= eads and can be mapped under the covers to any number of physical threads. = The actual mapping depends on the scheduler, but the outcome of dataflow al= gorithms doesn't depend on the actual scheduling.
Here's what you gain by using Dataflow Concurrency (by Jonas Boné= r http://www.jonasboner.com ):
This doesn't sound bad, does it?
If you'd like to know more on this interesting concept, check out the Dataflow concurrency section of the User Guide.