O'Reilly logo

Mastering Concurrency Programming with Java 9 - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dataflow

Dataflows provide safe channels to share data between producers and consumers. The most basic element of a dataflow is dataflow variables. You just create an object of the Dataflows class and then we can define variables on it. These variables have two important characteristics:

  • You can only set the value once
  • When a task tries to use the value of a dataflow's variable, its execution thread is blocked until the variable has a value

The benefits you can obtain with dataflow variables are:

  • You don't have race conditions
  • You don't need to use locks or other synchronization mechanisms explicitly
  • If there's a deadlock provoked by dataflow's variables, you can determine its cause

Let's see an example of how dataflow variables work. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required