清理 Java 中的锁定 (.lck) 文件 8
Cleaning up lock (.lck) files in Java 8
似乎 java 8 对锁定文件的处理方式进行了更改,这导致我积累了大量的 .lck 文件。
我想通过向我的应用程序添加一些代码来解决这个问题,以便在每次运行时清理输出目录中的锁定文件。 Java 但是不会保持此文件处于打开状态,这意味着如果我打开我的应用程序的第二个实例(常见用例),那么这将导致它删除锁定文件并在尝试重新使用相同日志时立即挂起文件作为另一个实例。
有没有人以更优雅的方式缓解这个问题?
确认这是至少 8u25 中的错误。 oracle 8u40 JRE 中的不良行为消失了。
Is java.util.logging.FileHandler in Java 8 broken?. Update your JDK 8 to update 40 or newer which contains the fix for JDK-8048020.
中对此进行了介绍
打开 FileHandler 时,您应该会看到锁定文件。如果您看到它们在 VM 退出后仍然存在,那是因为 FileHandler 未关闭,VM 在处理程序关闭挂钩 运行 时停止或崩溃,或者在 I/O 时发生异常试图删除它们。
当涉及到 FileHandler 使用的 FileLock 的实现时,您 运行 所在的平台也会发挥作用。 FileLock 文档附带以下警告:
Whether or not a lock actually prevents another program from accessing the content of the locked region is system-dependent and therefore unspecified. The native file-locking facilities of some systems are merely advisory, meaning that programs must cooperatively observe a known locking protocol in order to guarantee data integrity. On other systems native file locks are mandatory, meaning that if one program locks a region of a file then other programs are actually prevented from accessing that region in a way that would violate the lock. On yet other systems, whether native file locks are advisory or mandatory is configurable on a per-file basis. To ensure consistent and correct behavior across platforms, it is strongly recommended that the locks provided by this API be used as if they were advisory locks.
这意味着 FileHandler 在不同平台上可以有不同的锁定行为。
与锁定文件相关的还有记录器的垃圾收集,它不会关闭附加的处理程序。这些问题包含在 JDK-8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed and JDK-6274920: JDK logger holds strong reference to java.util.logging.Logger instances.
似乎 java 8 对锁定文件的处理方式进行了更改,这导致我积累了大量的 .lck 文件。
我想通过向我的应用程序添加一些代码来解决这个问题,以便在每次运行时清理输出目录中的锁定文件。 Java 但是不会保持此文件处于打开状态,这意味着如果我打开我的应用程序的第二个实例(常见用例),那么这将导致它删除锁定文件并在尝试重新使用相同日志时立即挂起文件作为另一个实例。
有没有人以更优雅的方式缓解这个问题?
确认这是至少 8u25 中的错误。 oracle 8u40 JRE 中的不良行为消失了。
Is java.util.logging.FileHandler in Java 8 broken?. Update your JDK 8 to update 40 or newer which contains the fix for JDK-8048020.
中对此进行了介绍打开 FileHandler 时,您应该会看到锁定文件。如果您看到它们在 VM 退出后仍然存在,那是因为 FileHandler 未关闭,VM 在处理程序关闭挂钩 运行 时停止或崩溃,或者在 I/O 时发生异常试图删除它们。
当涉及到 FileHandler 使用的 FileLock 的实现时,您 运行 所在的平台也会发挥作用。 FileLock 文档附带以下警告:
Whether or not a lock actually prevents another program from accessing the content of the locked region is system-dependent and therefore unspecified. The native file-locking facilities of some systems are merely advisory, meaning that programs must cooperatively observe a known locking protocol in order to guarantee data integrity. On other systems native file locks are mandatory, meaning that if one program locks a region of a file then other programs are actually prevented from accessing that region in a way that would violate the lock. On yet other systems, whether native file locks are advisory or mandatory is configurable on a per-file basis. To ensure consistent and correct behavior across platforms, it is strongly recommended that the locks provided by this API be used as if they were advisory locks.
这意味着 FileHandler 在不同平台上可以有不同的锁定行为。
与锁定文件相关的还有记录器的垃圾收集,它不会关闭附加的处理程序。这些问题包含在 JDK-8060132: Handlers configured on abstract nodes in logging.properties are not always properly closed and JDK-6274920: JDK logger holds strong reference to java.util.logging.Logger instances.