In this code, shutdown is a non volatile variable in Holder class. In Test object, an holder object is declared as volatile. If I update the shutdown variable, would it have the same effect as a volatile variable in Test class? that is to say, Will other threads immediately see the change after it is updated in one thread.
class Test {
volatile Holder holder = new Holder();
public void func() {
List<Thread> list = new ArrayList<Thread>();
for (int i = 0; i < 10; i++) {
list.add(new Thread() {
public void run() {
while (holder.shutdown) {
if (...) {
holder.shutdown = true;
}
}
}
});
}
for (Thread thread : list) {
thread.start();
}
}
class Holder {
boolean shutdown = false;
}
}