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
35                      .nanoTime()) {
36                  logger.info("in time loop");
37              }
38  
39              logger.info("before 2nd sleep");
40  
41              try {
42                  sleep(1000);
43              } catch (InterruptedException e) {
44                  logger.info("While sleeping", e);
45                  e.printStackTrace();
46                  break;
47              }
48              logger.info("after sleep");
49          }
50          logger.info("exiting WHILE");
51  
52      }
53  }