Follow these steps to implement the example:
- First, implement the shared data object. Create a class named Position with two integer attributes, namely x and y. You have to include the methods to get and set the values of the attributes. Its code is very simple so it is not included here.
- Now let's implement the Writer task. It implements the Runnable interface and it will have two attributes: a Position object named position and StampedLock named lock. They will be initialized in the constructor:
public class Writer implements Runnable { private final Position position; private final StampedLock lock; public Writer (Position position, StampedLock lock) { this.position=position; this.lock=lock; }
- Implement the ...