I have a class ConfigService
. The field config
in this class is designated as volatile
. It is assumed that several threads will read config
using getConfig()
, and one thread will update using update()
. Will reader threads see new values in config
object if a new newConfig
object is assigned in the config
field?
public class ConfigService{
private volatile Config config = new Config();
public updateConfig(Config newConfig){
config = newConfig;
}
public Config getConfig() {
return config;
}
}
public class Config{
private Integer myInt;
private String myString;
public Integer getMyInt() {
return myInt;
}
public String getMyString() {
return myString;
}
}