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

31 lines
577 B
Java

package chapter1.cretans;
import org.junit.Test;
/*
* update is now synchronized. Will it still WTF ?
*/
public class SynchronizedCretan extends CretanAttack{
public double value;
public SynchronizedCretan(double value) {
super(value);
}
@Test
public void test() {
SynchronizedCretan instance = new SynchronizedCretan(0);
instance.test();
}
public synchronized void update() {
value++;
}
public void compare() {
if (value != value) {
System.out.println("WTF?");
}
}
}