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;
15  
16  import java.util.Date;
17  import java.util.concurrent.ScheduledThreadPoolExecutor;
18  import java.util.concurrent.TimeUnit;
19  
20  import org.slf4j.Logger;
21  import org.slf4j.LoggerFactory;
22  
23  import ch.qos.logback.classic.LoggerContext;
24  import ch.qos.logback.classic.joran.JoranConfigurator;
25  import ch.qos.logback.core.joran.spi.JoranException;
26  import ch.qos.logback.core.util.StatusPrinter;
27  
28  public class LBCORE63 extends Thread {
29      private final static String LOGGER_CONFIGURATION_FILE = "./src/test/input/issue/lbcore63.xml";
30      private final Logger logger = LoggerFactory.getLogger(LBCORE63.class);
31  
32      private final long start;
33  
34      public LBCORE63() throws JoranException {
35          start = new Date().getTime();
36          LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
37          JoranConfigurator configurator = new JoranConfigurator();
38          lc.reset();
39          configurator.setContext(lc);
40          configurator.doConfigure(LOGGER_CONFIGURATION_FILE);
41          StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
42      }
43  
44      public void start() {
45          ScheduledThreadPoolExecutor ex1 = new ScheduledThreadPoolExecutor(1);
46          ScheduledThreadPoolExecutor ex2 = new ScheduledThreadPoolExecutor(1);
47          ScheduledThreadPoolExecutor ex3 = new ScheduledThreadPoolExecutor(1);
48          ScheduledThreadPoolExecutor ex4 = new ScheduledThreadPoolExecutor(1);
49          ScheduledThreadPoolExecutor ex5 = new ScheduledThreadPoolExecutor(1);
50          ex1.scheduleAtFixedRate(new Task("EX1"), 10, 10, TimeUnit.MICROSECONDS);
51          ex2.scheduleAtFixedRate(new Task("EX2"), 10, 10, TimeUnit.MICROSECONDS);
52          ex3.scheduleAtFixedRate(new Task("EX3"), 10, 10, TimeUnit.MICROSECONDS);
53          ex4.scheduleAtFixedRate(new Task("EX4"), 10, 10, TimeUnit.MICROSECONDS);
54          ex5.scheduleAtFixedRate(new Task("EX5"), 10, 10, TimeUnit.MICROSECONDS);
55  
56          super.start();
57      }
58  
59      public void run() {
60          try {
61              while (true) {
62                  logger.debug("[MAIN] {}", new Date().getTime() - start);
63                  Thread.sleep(10);
64              }
65          } catch (InterruptedException e) {
66              logger.info("[MAIN]: Interrupted: {}", e.getMessage());
67          }
68      }
69  
70      public static void main(String[] args) {
71          try {
72              LBCORE63 main = new LBCORE63();
73              main.start();
74          } catch (JoranException e) {
75              System.out.println("Failed to load application: " + e.getMessage());
76          }
77      }
78  
79      class Task implements Runnable {
80          private final Logger logger = LoggerFactory.getLogger(Task.class);
81          // private final Logger logger_main = LoggerFactory.getLogger(LBCORE63.class);
82          final String name;
83          private final long start;
84  
85          int counter = 0;
86          public long diff;
87  
88          public Task(final String name) {
89              this.name = name;
90              start = new Date().getTime();
91          }
92  
93          public void run() {
94              counter++;
95              diff = new Date().getTime() - start;
96              logger.debug("counter={}", counter);
97              // logger_main.debug("[MAIN] - [{}] {}", name, new Date().getTime() - start);
98          }
99      }
100 }