All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.heavenark.infrastructure.log.hook.ArkLogHookReg Maven / Gradle / Ivy

The newest version!
package com.heavenark.infrastructure.log.hook;

import com.heavenark.infrastructure.log.ArkLogThread;
import com.heavenark.infrastructure.log.component.ArkLogRecord;

/**
 * Ark-Log shutdown hook
 *
 * @author 冰糕Luminous BGLuminous Luminous
 * @since 3.0.0 2022-03-25
 */
public class ArkLogHookReg {
  /** register flag */
  private boolean registered = false;

  /** constructor */
  private ArkLogHookReg() {}

  /**
   * Get Ark-Log util instance
   *
   * @return util instance
   */
  public static ArkLogHookReg instance() {
    return ArkLogHookReg.Holder.INSTANCE;
  }

  /** register hook */
  public static void regShutdownHook() {
    if (instance().registered) {
      return;
    }
    Runtime.getRuntime().addShutdownHook(new ArkLogShutdownHook());
    instance().registered = true;
  }

  private static class ArkLogShutdownHook extends Thread {
    /**
     * If this thread was constructed using a separate Runnable run object, then that
     * Runnable object's run method is called; otherwise, this method does
     * nothing and returns.
     *
     * 

Subclasses of Thread should override this method. * * @see #start() */ @Override public void run() { try { Thread.sleep(1000); ArkLogThread.shutdown(); ArkLogRecord.shutdown(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } /** Initialization on Demand Holder */ private static class Holder { public static final ArkLogHookReg INSTANCE = new ArkLogHookReg(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy