This is a webapp running on Tomcat, using Guice. According to the docs we should be able to call ResourceBundle.clearCache();
to clear the ResourceBundle cache and presumably get the latest from the bundle property files.
We have also tried the following:
Class klass = ResourceBundle.getBundle("my.bundle").getClass().getSuperclass();
Field field = klass.getDeclaredField("cacheList");
field.setAccessible(true);
ConcurrentHashMap cache = (ConcurrentHashMap) field.get(null);
cache.clear(); // If i debug here I can see the cache is now empty!
and
ResourceBundle.clearCache(this.class.getClassLoader());
The behavior that I am expecting is:
So question is, how is ResourceBundle.clearCache() actually working ? And is there some generic file cache we need to clear also ?
This worked for me:
ResourceBundle.clearCache();
ResourceBundle resourceBundle= ResourceBundle.getBundle("YourBundlePropertiesFile");
String value = resourceBundle.getString("your_resource_bundle_key");
Notes:
ResourceBundle.getBundle()
method after invoking clearCache()
method.