in Java, why does the code b = = (b = a) not always return true? in a multithreaded environment
a can be modified by multiple threads.
b initializes to b = a
when printing b = = (b = a), the result is not necessarily true.
however, isn"t the priority of the operator b = an and then b = = b?
the code is as follows:
public class Demo implements Runnable{
public static double a = 0;
@Override
public void run() {
a = Math.random()*100;
double b = a;
System.out.println(b == (b = a));
}
public static void main(String args[]) {
for(int i=0;i<10;iPP) {
new Thread(new Demo()).start();
}
}
}
print result:
false
true
true
true
false
true
false
true
true
true