Below I've implemented the Multiton
pattern but I think this question applies equally to the Singleton
pattern:
private static ConcurrentHashMap<String, LocatorDAO> instances = new ConcurrentHashMap<String, LocatorDAO>();
public static LocatorDAO getInstance(String page String field)
{
String instanceID = page + " " + field;
LocatorDAO result = instances.get(instanceID);
if (result == null)
{
LocatorDAO m = new LocatorDAO(page, field);
result = instances.putIfAbsent(instanceID, m);
if (result == null)
result = m;
}
return result;
}
I would like to modify this design by instantiating a new instance every 300 seconds - so if 300 seconds passed from the time we instantiated the previous instance I would like to instantiate it again (or if the instance was never instantiated).
How could this be done?