C
Christopher Benson-Manica
I, in my naivete, have thought that the classes in
java.util.concurrent.atomic were intended for situations like
class foo {
private int bar=0;
synchronized public int getBar() {
return bar;
}
synchronized public void incrementBar() {
bar++;
}
}
, which can be refactored as
class foo {
private AtomicInteger bar=new AtomicInteger();
public int getBar() {
return bar.get();
}
public void incrementBar() {
bar.getAndIncrement();
}
}
Does this example miss the real point of why the
java.util.concurrent.atomic classes exist?
java.util.concurrent.atomic were intended for situations like
class foo {
private int bar=0;
synchronized public int getBar() {
return bar;
}
synchronized public void incrementBar() {
bar++;
}
}
, which can be refactored as
class foo {
private AtomicInteger bar=new AtomicInteger();
public int getBar() {
return bar.get();
}
public void incrementBar() {
bar.getAndIncrement();
}
}
Does this example miss the real point of why the
java.util.concurrent.atomic classes exist?