有個(gè)大師說過一句話,有人的地方就有江湖,有江湖的地方就有斗爭(zhēng)。今天在java eys就看到了一場(chǎng)Resourcebundle引起的口角,集體見:
http://www.javaeye.com/topic/6417?page=1.
這個(gè)問題在jdk1.6已經(jīng)不存在
clearCache
public static final void clearCache()
- Removes all resource bundles from the cache that have been loaded using the caller's class loader.
- Since:
- 1.6
- See Also:
ResourceBundle.Control.getTimeToLive(String,Locale)
clearCache
public static final void clearCache(ClassLoader loader)
- Removes all resource bundles from the cache that have been loaded using the given class loader.
- Parameters:
loader
- the class loader- Throws:
NullPointerException
- ifloader
is null- Since:
- 1.6
- See Also:
ResourceBundle.Control.getTimeToLive(String,Locale)
在1.5,1.4怎么辦呢:
Class klass = ResourceBundle.getBundle("your.Bundle").getClass().getSuperclass();
Field field = klass.getDeclaredField("cacheList");
field.setAccessible(true);
sun.misc.SoftCache cache = (sun.misc.SoftCache)field.get(null);
cache.clear();
field.setAccessible(false);
這樣就可以清楚cache.