View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.issue.lbcore_155;
15  
16  import org.slf4j.Logger;
17  import org.slf4j.LoggerFactory;
18  
19  /**
20   * @author Ceki Gülcü
21   */
22  public class OThread extends Thread {
23  
24      static int NANOS_IN_MILLI = 1000 * 1000;
25  
26      static int WAIT_MILLIS = 10;
27  
28      Logger logger = LoggerFactory.getLogger(this.getClass());
29  
30      public void run() {
31  
32          while (!isInterrupted()) {
33              long start = System.nanoTime();
34              for (long now = System.nanoTime(); now < start + 2 * WAIT_MILLIS * NANOS_IN_MILLI; now = System.nanoTime()) {
35                  logger.info("in time loop");
36              }
37  
38              logger.info("before 2nd sleep");
39  
40              try {
41                  sleep(1000);
42              } catch (InterruptedException e) {
43                  logger.info("While sleeping", e);
44                  e.printStackTrace();
45                  break;
46              }
47              logger.info("after sleep");
48          }
49          logger.info("exiting WHILE");
50  
51      }
52  }