I'm trying to implement singleton which is going to cache and validate configuration of map reduce jobs in hadoop. Let's name it ConfigurationManager
.
Here is what I have for now:
public class ConfigurationManager {
private static ConfigurationManager instance;
private static final String CONF_NAME = "isSomethingEnabled";
private boolean isSomethingEnabled;
private ConfigurationManager(Configuration configuration) {
this.isSomethingEnabled= configuration.getBoolean(CONF_NAME, false);
}
public static ConfigurationManager get(Configuration configuration) {
if (instance == null) {
synchronized (ConfigurationManager.class) {
if (instance == null) {
instance = new ConfigurationManager(configuration);
}
}
}
return instance;
}
public boolean isSomethingEnabled() {
return isSomethingEnabled;
}
}
As you can see it is designed to be thread-safe. Moreover it is not standard singleton: I separated initialization and accessor methods not to enforce presence of hadoop's Configuration
instance on get
call. So to use it I prematurely call init
in the ancestor of Tool
and then trying to access my singleton using get
in reducers (like this ConfigurationManager.get().isSomethingEnabled()
), but for some reasons get
returns null
. Could somebody, please, explain such a behaviour? Maybe maps/reducers are initiated as separate processes?
Aucun commentaire:
Enregistrer un commentaire