there is an example in the jboss docs showing how to deploy a hashMap via a MBean. Here is my question.
If I have a hashmap that is created via a reload properties method inside the MBean (reloading properties from an xml document and creating a Object that is stored in the key portion of the hashmap) what happens when I click on the reload if someone is trying to access it? would it be syncronized? i.e. do I have to do the following clone the hashmap? or am I ok.
here is some code:
private void rebind() throws NamingException {
InitialContext ic = new InitialContext();
Name fullName = ic.getNameParser("").parse(jndiName);
System.out.println("fullName=" + fullName);
NonSerializableFactory.rebind(fullName, myHashMap, true);
}
public void reloadProperties() throws Exception {
try {
Unmarshaller um = new Unmarshaller(ServiceActionProperties.class);
ServiceActionProperties prop = (ServiceActionProperties) um.unmarshal(new InputSource(
new FileReader(getFileLocation())));
contextMap.clear();
String serviceName = null;
for (int i = 0; i < prop.getServiceCount(); i++) {
serviceName = prop.getService(i).getName();
actions = new ArrayList();
for(int x = 0;x<prop.getService(i).getServiceActionCount();x++)
{
actions.add(prop.getService(i).getServiceAction(x));
}
contextMap.put(serviceName,actions);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("FileLoadError : \n " + e.getMessage());
}
}
notice in the 2nd snip there is a line that says "contextMap.clear();" what's going to happen at that point if someone/thing is using it?
oops that second should be reference myHashMap not contextMap. :)