Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

resourcebundle

 
dan volfman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
dan volfman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ; - )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic