开发者

canonical file path in java - optimization problem?

开发者 https://www.devze.com 2023-04-05 20:10 出处:网络
My file structure has a symbolic link to a directory /home/me/myDir -> /some/other/dir. This link gets updated by another process and the notifies my process. Upon notification I attempt to get the n

My file structure has a symbolic link to a directory /home/me/myDir -> /some/other/dir. This link gets updated by another process and the notifies my process. Upon notification I attempt to get the new canonical path:

public static String getPath()
{
   File file = new File("/home/me/myDir");
   if(file.exists())
   {
      try
      {
         String canonical = file.getCanonicalPath();
         return canonical;
      }
      catch ...
   }

}

The problem is that after the link is changed (an i have verified it changes) it is taking 3-5 times of calling the above getPath() method for to actually get the new path before that the previous path is returned. The开发者_StackOverflow only thing I can think of is that java might be optimizing this method and returning the old path. Any ideas or insight is greatly appreciated.


Try disabling Java's canonicalization cache. This can be done by setting the system properties sun.io.useCanonCaches and sun.io.useCanonPrefixCache to false.

By default, canonical file names are cached for 30 seconds (read from source here).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号