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

Running Java Pathfinder

Once we have installed JPF, let's see how we can use it to test a concurrent application. First, we have to implement a concurrent application. In our case, we will use a Data class with an internal int value. It will be initialized with 0 and will have an increment() method to increment the value.

Then, we will have a task named NumberTask , that implements the Runnable interface that will increment the value of a Data object ten times.

public class NumberTask implements Runnable { 
 
  private Data data; 
 
  public NumberTask (Data data) { 
    this.data=data; 
  } 
 
  @Override 
  public void run() { 
 
    for (int i=0; i<10; i++) { 
      data.increment(10); 
    } 
  } 
 
} 

Finally, we have the MainNumber class, which implements the main() method. We will ...

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