Is this technically thread safe despite being mutable?
Posted
by Finbarr
on Stack Overflow
See other posts from Stack Overflow
or by Finbarr
Published on 2010-05-05T07:46:15Z
Indexed on
2010/05/05
7:48 UTC
Read the original article
Hit count: 248
Yes, the private member variable bar should be final right? But actually, in this instance, it is an atomic operation to simply read the value of an int. So is this technically thread safe?
class foo {
private int bar;
public foo(int bar) {
this.bar = bar;
}
public int getBar() {
return bar;
}
}
// assume infinite number of threads repeatedly calling getBar on the same instance of foo.
© Stack Overflow or respective owner