Esempio n. 1
0
/**
 * ShutdownHook implementation that stops the Logback context after a specified delay. The default
 * delay is 0 ms (zero).
 *
 * @author Mike Reinhold
 */
public class DelayingShutdownHook extends ShutdownHookBase {
  /** The default is no delay before shutdown. */
  public static final Duration DEFAULT_DELAY = Duration.buildByMilliseconds(0);

  /** The delay in milliseconds before the ShutdownHook stops the logback context */
  private Duration delay = DEFAULT_DELAY;

  public DelayingShutdownHook() {}

  public Duration getDelay() {
    return delay;
  }

  /**
   * The duration to wait before shutting down the current logback context.
   *
   * @param delay
   */
  public void setDelay(Duration delay) {
    this.delay = delay;
  }

  public void run() {
    try {
      Thread.sleep(delay.getMilliseconds());
    } catch (InterruptedException e) {
    }
    super.stop();
  }
}