aspose file tools*
The moose likes Java in General and the fly likes resourcebundle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "resourcebundle" Watch "resourcebundle" New topic
Author

resourcebundle

dan volfman
Greenhorn

Joined: Jan 15, 2010
Posts: 6
hi
if i use ResourceBundle.getbundle("aaa"), more than one time, does the bundle loads each time i use this, or only the first time?


thanks.
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
Look into the API doc:
http://java.sun.com/javase/6/docs/api/java/util/ResourceBundle.html
Cache Management

Resource bundle instances created by the getBundle factory methods are cached by default, and the factory methods return the same resource bundle instance multiple times if it has been cached. getBundle clients may clear the cache, manage the lifetime of cached resource bundle instances using time-to-live values, or specify not to cache resource bundle instances. Refer to the descriptions of the getBundle factory method, clearCache, ResourceBundle.Control.getTimeToLive, and ResourceBundle.Control.needsReload for details.


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
dan volfman
Greenhorn

Joined: Jan 15, 2010
Posts: 6
ok, thanks.
now, if i use bundle to get a properties file. how can i make the bundle reload when the properties file changes? or reload every defined time?

clearCache() doesnt do the job..

Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
I tried to do something similar a few years ago and never got it running. Afaik a resource bundle cannot be easily updated / reread. And you cannot simply extend ResourceBundle and provide your own implementation because most of it's members are private (you'd have to implement it from scratch).

To refresh the contents of a bundle you have to clear the cache (even that wasn't possible before Java 6!) and reread the bundle:

Of course, for the example to work you have to add '.' (executing directory) to your classpath ; - )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: resourcebundle