简体   繁体   English

java.io.IOException:无法获取锁定

[英]java.io.IOException: Couldn't get lock for

Get error as 得到错误

"java.io.IOException: Couldn't get lock for ..\\log\\abc.log", not sure why this happen. “java.io.IOException:无法锁定.. \\ log \\ abc.log”,不知道为什么会发生这种情况。

Can somebody help me out? 有人可以帮帮我吗? Thank you 谢谢

        logger = LogManager.getLogManager().getLogger(className);
        FileHandler logFile = new FileHandler(file);

        // create txt Formatter
        SimpleFormatter formatterTxt = new SimpleFormatter();
        logFile.setFormatter(formatterTxt);         
        logger.addHandler(logFile);

@Catheryan @Catheryan

I also had the same issue. 我也有同样的问题。 For me issue was: 对我来说问题是:

private static final String FILE_PATH="/home/jeril/Logs.log";
handler = new FileHandler(FILE_PATH);

FILE_PATH was WRONG FILE_PATH错了

This issue is a long standing bug in FileHandler (reported way back in March 2005, in Java 4): 这个问题是FileHandler一个长期存在的错误(2005年3月报道,在Java 4中):

JDK-6244047 : impossible to specify directories to logging FileHandler unless they exist JDK-6244047:除非存在,否则无法指定记录FileHandler的目录

Quoting from the description of this bug: 引用此bug的描述:

If you specify a patern to the FileHandler that contains directories that don't currently exist then the FileHandler will fail to initialise even if the directories can be created 如果为FileHandler指定一个包含当前不存在的目录的patern,那么即使可以创建目录,FileHandler也将无法初始化

Its mentioned that it has been fixed in Java 8. For versions earlier than 8, the workaround is to either not use any directory in the pattern used for a FileHandler or use a directory which actually exists on the disk. 它提到它已在Java 8中修复。对于早于8的版本,解决方法是不使用用于FileHandler的模式中的任何目录或使用磁盘上实际存在的目录。

我认为这是因为有一个以上的记录器实例打开它或其他一些外部应用程序打开它带有读/写锁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM