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.multiJVM;
15  
16  import org.slf4j.Logger;
17  
18  public class LoggingThread extends Thread {
19      static String msgLong = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
20  
21      final long len;
22      final Logger logger;
23      private double durationPerLog;
24  
25      public LoggingThread(Logger logger, long len) {
26          this.logger = logger;
27          this.len = len;
28      }
29  
30      public void run() {
31          long before = System.nanoTime();
32          for (int i = 0; i < len; i++) {
33              logger.debug(msgLong + " " + i);
34              // try {
35              // Thread.sleep(100);
36              // } catch (InterruptedException e) {
37              // }
38          }
39          // in microseconds
40          durationPerLog = (System.nanoTime() - before) / (len * 1000.0);
41      }
42  
43      public double getDurationPerLogInMicroseconds() {
44          return durationPerLog;
45      }
46  
47  }