concurrencypuzzlers/src/chapter1/cretans/SynchronizedCretan2.java
2019-09-20 13:34:33 +02:00

28 lines
575 B
Java

package chapter1.cretans;
/*
* now both read and update are synchronized
*/
public class SynchronizedCretan2 extends CretanAttack {
public double value;
public SynchronizedCretan2(double value) {
super(value);
}
public static void main(String[] args) {
SynchronizedCretan2 instance = new SynchronizedCretan2(0);
instance.test();
}
public synchronized void update() {
value++;
}
public synchronized void compare() {
if (value != value) {
System.out.println("WTF?");
}
}
}