{
if(formats == null)
formats = new Hashtable();
}
MessageFormat format = null;
// Check to see if we already have a requested MessageFormat cached
// and construct it if we don't
// NOTE: this block statement should be synchronized. However
// concurrent creation of two formats will have no harmful
// consequences, and we avoid a performance hit.
/* synchronized(formats) */
{
format = (MessageFormat)formats.get(key);
if(format == null)
{
format = new MessageFormat(((ResourceBundle)object).getString(key));
format.setLocale(getBundle().getLocale());
formats.put(key, format);
}
}
// Perform the formatting. We synchronize on it in case it
// contains date formatting, which is not thread-safe.
synchronized(format)
{
return format.format(params);
}
}