How to reload ResourceBundle (not from cache)??

Does anyone know how to get a "fresh" ResourceBundle instead of the cached version?? I have read some solution (as described below that clears the sun.misc.SoftCache) which is working, but not a good coding practice.
Class klass = ResourceBundle.getBundle("resources.framework").getClass().getSuperclass();
Field field = klass.getDeclaredField("cacheList");
field.setAccessible(true);
sun.misc.SoftCache cache = (sun.misc.SoftCache)field.get(null);
cache.clear();
It is recommended by Sun NOT TO USE the sun.* package in the application codes because it is not supported by all other vendors and might not even be supported in the future relase of JDK. Does anyone know whetehr latest (e.g.,JDK 1.4) has changed the implementation to use standard pacakges or any other ways to not use the cached version, but load a fresh ResourceBundle from properties file??
Thanks for your help.
Frank Wang

Here you have a ReloadablePropertyResourceBundle that uses the cache if the file has not been changed. Other case, reload the properties file.
import java.util.ResourceBundle;
import java.util.PropertyResourceBundle;
import java.util.Locale;
import java.util.Vector;
import java.io.InputStream;
import java.util.Enumeration;
import java.lang.ref.SoftReference;
import java.util.MissingResourceException;
import java.net.URL;
import java.net.URLConnection;
import java.io.IOException;
import java.io.File;
public class ReloadablePropertyResourceBundle extends PropertyResourceBundle{
private static final String FILE_SUFIX = ".properties";
     private static sun.misc.SoftCache cacheList = new sun.misc.SoftCache();
     private static final AGResourceCacheKey cacheKey = new AGResourceCacheKey();
     private static class AGResourceCacheKey implements Cloneable {
          private SoftReference loaderRef;
          private String searchName;
          private int hashCodeCache;
          public boolean equals(Object other) {
               if (this == other) {
                    return true;
     if (null == other) {
                    return false;
     if (!(other instanceof AGResourceCacheKey)) {
                    return false;
     AGResourceCacheKey otherEntry = (AGResourceCacheKey)other;
               boolean result = hashCodeCache == otherEntry.hashCodeCache;
               if (result) {
                    //are the names the same
                    result = searchName.equals(otherEntry.searchName);
                    if (result) {
                         final boolean hasLoaderRef = loaderRef != null;
                         //are refs (both non-null) or (both null)
                         result = (hasLoaderRef && (otherEntry.loaderRef != null)) || (loaderRef == otherEntry.loaderRef);
                         //if both non-null, check that they reference the same loader
                         if (result && hasLoaderRef) {
                              result = loaderRef.get() == otherEntry.loaderRef.get();
               return result;
     public int hashCode() {
          return hashCodeCache;
          public Object clone() {
               try {
                    return super.clone();
               } catch (CloneNotSupportedException e) {
                    throw new InternalError();
          public void setKeyValues(ClassLoader loader, String searchName) {
               this.searchName = searchName;
               hashCodeCache = searchName.hashCode();
               if (loader == null) {
                    this.loaderRef = null;
               } else {
                    loaderRef = new SoftReference(loader);
                    hashCodeCache ^= loader.hashCode();
     private static final Object NOLOADER_NOTFOUND = new Integer(-1);
     private long lastModified = 0;
     private java.lang.String fileName = "";
public ReloadablePropertyResourceBundle(java.io.InputStream stream) throws java.io.IOException {
     super(stream);
public ReloadablePropertyResourceBundle(java.io.InputStream stream, String fileName, long lastModified) throws java.io.IOException {
     super(stream);
     this.fileName = fileName;
     this.lastModified = lastModified;
private static ClassLoader getLoader() {
     Class[] stack = new SecurityManager() {  
                    public Class[] getClassContext() {     
                              return super.getClassContext();
                    .getClassContext();          
     /* Magic number 2 identifies our caller's caller */
     Class c = stack[2];
     ClassLoader cl = (c == null) ? null : c.getClassLoader();
     if (cl == null) {
          cl = ClassLoader.getSystemClassLoader();
     return cl;
public static ResourceBundle getResourceBundle(String baseName) throws MissingResourceException {
     return getResourceBundle(baseName, Locale.getDefault());     
public static ResourceBundle getResourceBundle(String baseName, Locale locale) throws MissingResourceException {
     return getResourceBundle(baseName, locale, getLoader());     
public static ResourceBundle getResourceBundle(String baseName, Locale locale, ClassLoader loader) throws MissingResourceException {
     StringBuffer localeName = new StringBuffer("_").append(locale.toString());
     if (locale.toString().equals(""))
          localeName.setLength(0);
     ResourceBundle lookup = searchBundle(baseName, localeName, loader, false);
     if(lookup == null)
          localeName.setLength(0);
          localeName.append("_").append( Locale.getDefault().toString() );
          lookup = searchBundle(baseName, localeName, loader, true);
          if( lookup == null )
               throw new MissingResourceException("Can't find resource for base name "
                                                       + baseName + ", locale " + locale,
                                                       baseName + "_" + locale,"");
     // No parents
     return lookup;
private static URL getUrl(final String name, final ClassLoader loader) {
URL url = (URL)java.security.AccessController.doPrivileged (new java.security.PrivilegedAction() {
          public Object run()
                    if (loader != null)
                         return loader.getResource(name);
                    else
                    return ClassLoader.getSystemResource(name);
     return url;
private static ResourceBundle searchBundle(String baseName, StringBuffer localeName, final ClassLoader loader, boolean includeBase)
     String localeStr = localeName.toString();
     String baseFileName = baseName.replace('.', '/');
     Object lookup = null;
     String searchName;
     Vector cacheCandidates = new Vector();
     int lastUnderbar;
     InputStream stream = null;
     URL url = null;
     long lastDate = 0;
     URLConnection urlCon = null;
     Object NOTFOUND;
     if (loader == null)
          NOTFOUND = NOLOADER_NOTFOUND;
     else
          NOTFOUND = loader;
     searchLoop:
     while (true)
          searchName = baseName + localeStr;
          // look the property file
          searchName = baseFileName + localeStr + FILE_SUFIX;
     final String resName = searchName;
     // look in the cache
          synchronized (cacheList) {
               cacheKey.setKeyValues(loader, searchName);
               lookup = cacheList.get(cacheKey);
               //If the value == the class loader, this
               //signifies that a prior search failed
               if( lookup == NOTFOUND ) {
                    localeName.setLength(0);
                    break searchLoop;
               if( lookup != null )
                    // Creation date
                    if (lookup instanceof ReloadablePropertyResourceBundle)
                         String fileName = ((ReloadablePropertyResourceBundle)lookup).fileName;
                    url = getUrl(fileName, loader);
                    if (url != null)
                              lastDate = new File(url.getFile()).lastModified();
                         if ((url != null && ((ReloadablePropertyResourceBundle)lookup).lastModified == lastDate) || lastDate == 0)
                              localeName.setLength(0);
                              break searchLoop;
                         else
                              url = null;
                              lookup = null;
                              cacheList.remove(cacheKey);
                    else
                         localeName.setLength(0);
                         break searchLoop;
               cacheCandidates.addElement(cacheKey.clone() );
               cacheKey.setKeyValues(null, "");
          if (url == null)
          url = getUrl(resName, loader);
     if (url != null)
               try
                    urlCon = url.openConnection();
               catch (Exception e){}
     if (urlCon != null)
               try
               stream = urlCon.getInputStream();
                    lastDate = new File(url.getFile()).lastModified();
               catch (IOException e)
          if( stream != null )
               // make sure it is buffered
               stream = new java.io.BufferedInputStream(stream);
               try {
                    lookup = (Object)new ReloadablePropertyResourceBundle(stream, resName, lastDate);
                    break searchLoop;
               catch (Exception e) {
               finally {
                    try {
                         stream.close();
                    catch (Exception e) {
                         // to avoid propagating an IOException back into the caller
                         // (I'm assuming this is never going to happen, and if it does,
                         // I'm obeying the precedent of swallowing exceptions set by the
                         // existing code above)
          //Chop off the last part of the locale name string and try again.
          lastUnderbar = localeStr.lastIndexOf('_');
          if( ((lastUnderbar==0)&&(!includeBase)) || (lastUnderbar == -1) ) {
               break;
          localeStr = localeStr.substring(0,lastUnderbar);
          localeName.setLength(lastUnderbar);
     // If we searched all the way to the base, then we can add
     // the NOTFOUND result to the cache. Otherwise we can say
     // nothing.
     if (lookup == null && includeBase == true)
          lookup = NOTFOUND;
     if( lookup != null )
          synchronized (cacheList) {
               // Add a positive result to the cache. The result may include
               // NOTFOUND
               for( int i=0; i<cacheCandidates.size(); i++ ) {
                    cacheList.put(cacheCandidates.elementAt(i), lookup);
     if( (lookup == NOTFOUND) || (lookup == null) )
          return null;
     else
          return (ResourceBundle)lookup;

Similar Messages

  • How to stop the Browser from caching my web pages

    Hi There
    Can anyone tell how to stop the browser from caching my jsp pages
    I am using
    <%response.setHeader("Cache-Control","no-cache");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0);
    %>
    but this does not work anduser is able to go back to the previous page
    which i dont want and i want the browser to display the message the page has expired
    Help appreciated
    Thanks
    Mumtaz

    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("max-age", 0);
    response.setDateHeader("Expires", 0);
    I have cut paste the code from my jsp which is working. There is one additional line. I do not know if that is the cause but there is no harm in trying that out.
    Srinivasan Ranganathan

  • How do i transfer notes from one phone to another

    how do i transfer notes from one phone to another

    I would recommend just backing up your old phone & then restoring the new one from that backup if you are planning to sell/give away the old one. Do NOT restore that phone until you're sure everything is on your new one, though, just in case!
    If you have 2 phones and want the same Notes on both, syncing via iCloud is probably better.
    ~Lyssa

  • HT1386 how do i sync notes from computer to ipad?

    how do i sync note from computer to ipad?

    See Here
    Syncing with iTunes
    From Here
    http://www.apple.com/support/ipad/syncing/

  • How do i sync Notes from 4 to 4S or to itunes

    how do i sync Notes from 4 to 4S or to Itunes?

    You don't sync Notes to Itunes.  But you can sync between 4 and 4s through iCloud.  Make sure your iCloud is activated.  SETTINGS / iCould / Notes turn it ON on both devices.

  • How do I transfer Notes from my iPhone4s and iPad to my new MacBook Pro?

    How do I transfer Notes from my iPhone4s and iPad to my new 13" MacBook Pro with retina display?

    Finally figured it out...
    1) Open mail/compose notes on your macbook...
    2) copy and paste every note from Outlook to a new note in Mail.
    3) Open iTunes. In Info/Advanced tick Notes. This will replace / copy all Notes from Mail to your iPhone...
    4) Voila! Notes are on iPhone...
    I must say in spite of all the fabulous advantages of a Macbook and an iPhone, syncing really does suck...
    Transferring data from another smartphone to a Mac or an iPhone is tough...
    Features like "one way / two way" sync for Phone / computer or allowing us to select which whose, phone or computer, will be considered more important so that you can choose whose data will overwrite the other, are not there in iTunes... This is something which really needs to be there...
    Anyways... problem solved for now...
    ciao...
    Jesal

  • HT201269 How do I transfer notes from my 3GS to my 4S?

    How do i transfer notes from my 3GS to my 4S

    Use iCloud, or back up the old device and restore the new from the backup. Email them to yourself. Many, many ways to do it.

  • How do I transfer notes from iPhone3 to iPhone5?

    how do I transfer notes from iPhone3 to iPhone5?

    Understood. "Notes" are on the iPhone3. These are notes that I typed into the iPhone3 "Notes".  I am using the iTunes program on the computer to sync. I want to move the iPhone3 notes to the iPhone5.
    Contacts and all the apps have been moved. I just cannot figure out how to move "Notes"

  • How do i transfer notes from my iPhone to my mac

    how do i transfer notes from my iPhone to my mac

    You have to use iCloud, or set it up through your email client if it's supported--like Gmail.

  • How can I sync notes from computer email (gmail) to iphone4?

    How can I sync notes from my Macbook email program (gmail) to my iphone4 ?

    There is no separate Notes app in OS X. If you select to sync notes on the Info pane, they will sync to the Mail app: Mail>Reminders>Notes.

  • How do I move Notes from one account to another?

    When I upgraded to Lion and ios5, all my Notes were on my Mac, iPhone and iPad, having been synched via USB and iTunes in the past. Some of these notes have been around for quite a while.
    Later, I edited a few notes and became aware that the chnages have not been synched to other devices. It turns out that somehow I have two acconts for notes on my ios devices - they are
    From My Mac - all the rest
    ICloud - 2 notes
    It seems that changes I make to notes that are in the From My Mac account do not get synched to the Mac or my other device. How can I change the account for those in the From My Mac account to the iCloudl account?

    Only notes in the iCloud account will sync with iCloud.  In order to move notes from other accounts you have to open each one, copy/paste the test into new notes created in the iCloud account, then delete the original in the other account.

  • How can I transfer "notes" from one icloud account to another, and other account questions

    Hey,
    I currently have 2 icloud accounts. (In total I have 4 seperate apple ids somehow, 1 @me.com, 1 @icloud.com, 1 @gmail.com, and 1 apple id. But that's a problem I'll talk about later).
    Right now, all of my notes got deleted from my iphone, but they are on the icloud account A: (@me.com account's icloud.) When I reconnect this account to my iphone, the notes are there. However, when I turn off note syncing in my iphone's icloud settings, I'm not prompted to "keep data on iphone" (like I am prompted with contacts). Instead, they are just deleted from the iphone. So there's no way to connect the icloud account A, download the data, and reconnect icloud account B.
    How can I get these notes from icloud account A to icloud account B (or just getting it from icloud account A to my iphone.)
    And while I'm at it, how can I get the @icloud account that was linked with the @me.com account to get linked to the @gmail.com account.
    Sorry if this is confusing.

    Let me rephrase my comment...  I used Windows to sync my data without icloud, we decided to switch to mac and purchased a $2000 osx driven machine only to find out apple has "secretly" disabled mobile sync services and replaced it with icloud syncing.  There was NO documentation stating this fact before my purchase, it was only realized when users started running into syncing issues that apple disclosed mavericks no longers uses mobile syncing services and "requires you to use icloud to sync device information" on this forum.
    They removed a integral part of my privacy without telling me, or warning me, before i spent money on non-refundable merchandice.
    These are not mindless, I was forced into mavericks when i purchased a new mac... All other versions of OSX provide modile syncing services.
    And I was not threatening lawsuit, i was stating a thought that this leavs apple open to a lawsuit for people who want their data kept private, they are FORCING the use of icloud now.

  • How can I get notes from my Ipad cloud to sync to my iphone?

    How can I sync previous "Notes" from my Ipad cloud to my Iphone?

    Welcome to the Apple Community.
    First check that all your settings are correct, that notes syncing (mail and notes on a computer) is checked on all devices (system preferences > iCloud on a mac and settings > iCloud on a iPhone, iPad or iPod).
    Make sure the notes you are adding are added to your 'iCloud' account and not an 'On My Mac', 'On My Phone'  or other non iCloud account (you can do this by checking in accounts on an iOS device, or the left side panel in mail on a computer), non iCloud notes will not sync.
    If you are sure that everything is set up correctly and your notes are in the iCloud group, you might try unchecking notes syncing (mail and notes on a computer) in the iCloud settings, restarting your device and then re-enabling notes syncing.

  • How do I transfer Notes from my Outlook Mac 2011 to my iPhone 4S (iOS 6)? I am using OSX 10.6.8 Snow Leopard on a MacBook Pro

    Hi,
    I want to know how I can transfer Notes in my Outlook: Mac 2011 to my iPhone 4S.
    Am using a Macbook Pro with OSX 10.6.8 Snow Leopard and my 4S is on iOS 6.
    Jesal

    Finally figured it out...
    1) Open mail/compose notes on your macbook...
    2) copy and paste every note from Outlook to a new note in Mail.
    3) Open iTunes. In Info/Advanced tick Notes. This will replace / copy all Notes from Mail to your iPhone...
    4) Voila! Notes are on iPhone...
    I must say in spite of all the fabulous advantages of a Macbook and an iPhone, syncing really does suck...
    Transferring data from another smartphone to a Mac or an iPhone is tough...
    Features like "one way / two way" sync for Phone / computer or allowing us to select which whose, phone or computer, will be considered more important so that you can choose whose data will overwrite the other, are not there in iTunes... This is something which really needs to be there...
    Anyways... problem solved for now...
    ciao...
    Jesal

  • How can I share notes from iPhone to MaCbook

    I can't share my notes from my iPhone to my MacBook. How do you do that?

    Hi grey and sorrow,
    Thanks for visiting Apple Support Communities.
    You can sync notes between your iOS devices. See this link for the steps:
    iOS: Syncing Notes
    http://support.apple.com/kb/HT4191
    Best Regards,
    Jeremy

Maybe you are looking for

  • Problems setting up Weblogic Server 9.2 with Oracle AQ

    We are in the process of upgrading from WLS81 to WLS92 and I'm currently trying to set up the environment. We have applications communicating with 3 different JMS-servers; Sonic, WMQ and Oracle AQ. For both Sonic and WMQ the connection seem to work f

  • Ipod restore error (1611)

    Hello, i am having trouble with my ipod touch 2nd gen. I got it all working and fine when i first got it. But one day, when i tried to charge it with my computer, it wouldnt recognize in my itunes. Then, i tried to do the 5 R's, then i finally restor

  • Time Machine Backup Stuck in a Loop?

    Since upgrading to ML I've noticed that my Time Machine backup icon seems to be in constant motion.  I've also noticed that it never seems to be backing up as it's been stuck at "427kb of 479mb" for the past hour.  I'm backing up to a Time Capsule an

  • Is there a way to link up my firewire 400 Audio I/O into USB3 or Thunderbolt?

    Hi all, I'm currently struggling trying to link my Firewire 400 Audio Interface to my new imac. There seems to have no easy way to link it up to either USB2/3 or Thunderbolt.? Cheers

  • Regarding Reports performance

    Hi All, Now i am working in Production system. How can i check the performance for reports. How can i find the report performance is low/high? Please let me know the details. Thanks Vasu.