Follow these steps to implement the example:
- Create a class named Incrementer and specify that it implements the Runnable interface:
public class Incrementer implements Runnable {
- Declare a private AtomicIntegerArray attribute named vector to store an array of integer numbers:
private final AtomicIntegerArray vector;
- Implement the constructor of the class to initialize its attribute:
public Incrementer(AtomicIntegerArray vector) { this.vector=vector; }
- Implement the run() method. Increment all the elements of the array using the getAndIncrement() method:
@Override public void run() { for (int i=0; i<vector.length(); i++){ vector.getAndIncrement(i); } }
- Create a class named Decrementer and specify that ...