*/
public static MapBuilder getMapBuilder(String name)
{
try
{
MapBuilder mb = (MapBuilder) mapBuilders.get(name);
// Use the 'double-check pattern' for syncing
// caching of the MapBuilder.
if (mb == null)
{
synchronized (mapBuilders)
{
mb = (MapBuilder) mapBuilders.get(name);
if (mb == null)
{
mb = (MapBuilder) Class.forName(name).newInstance();
// Cache the MapBuilder before it is built.
mapBuilders.put(name, mb);
}
}
}
// Build the MapBuilder in its own synchronized block to
// avoid locking up the whole Hashtable while doing so.
// Note that *all* threads need to do a sync check on isBuilt()
// to avoid grabing an uninitialized MapBuilder. This, however,
// is a relatively fast operation.
synchronized (mb)
{
if (!mb.isBuilt())
{
try
{
mb.doBuild();
}
catch (Exception e)
{
// need to think about whether we'd want to remove
// the MapBuilder from the cache if it can't be