Class ShutdownCloser

java.lang.Object
dev.enola.common.ShutdownCloser

public final class ShutdownCloser extends Object
A utility class for gracefully closing resources (AutoCloseable instances) when the Java Virtual Machine (JVM) shuts down. Typically used in main() methods to ensure that all resources are closed when the application is terminated with Ctrl+C or a kill signal (which will not run try-with-resources).
  • Method Details

    • add

      public static void add(AutoCloseable resource)
      Adds an AutoCloseable resource to the static set for graceful shutdown.
      Parameters:
      resource - The resource to be closed on JVM shutdown.