java.util.Date.toString() really slow?

Per Bothner per@bothner.com
Mon Jun 3 21:39:00 GMT 2002


Bryce McKinlay wrote:
> Presumably it would be reasonable to cache negative results for resource 
> bundle (and class?) lookups. People don't expect to be able to 
> dynamically add new resource bundles to a running application, right?

How about caching the default bundle:

private static final ResourceBundle defaultBundle =
   ResourceBundle.getBundle(bundleName, Locale.getDefault());

private static synchronized Calendar
getInstance(TimeZone zone, Locale locale, ResourceBundle bundle)
{
   String calendarClassName = bundle.getString("calendarClass");
   if (calendarClassName != null)
     ...
}

public static Calendar getInstance()
{
   return getInstance(TimeZone.getDefault(), Locale.getDefault(),
     defaultBundle);
}

public static Calendar getInstance(TimeZone zone)
{
   return getInstance(zone, Locale.getDefault(), defaultBundle);
}
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/



More information about the Java mailing list