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.core.issue;
15  
16  import ch.qos.logback.core.contention.ThreadedThroughputCalculator;
17  import ch.qos.logback.core.issue.SelectiveLockRunnable.LockingModel;
18  
19  /**
20   * Short sample code testing the throughput of a fair lock.
21   * 
22   * @author Joern Huxhorn
23   * @author Ceki Gulcu
24   */
25  public class NoLockThroughput {
26  
27      static int THREAD_COUNT = 3;
28      static long OVERALL_DURATION_IN_MILLIS = 2000;
29  
30      public static void main(String args[]) throws InterruptedException {
31  
32          ThreadedThroughputCalculator tp = new ThreadedThroughputCalculator(OVERALL_DURATION_IN_MILLIS);
33          tp.printEnvironmentInfo("NoLockThroughput");
34  
35          for (int i = 0; i < 2; i++) {
36              tp.execute(buildArray(LockingModel.NOLOCK));
37          }
38  
39          tp.execute(buildArray(LockingModel.NOLOCK));
40          tp.printThroughput("No lock:   ", true);
41      }
42  
43      static SelectiveLockRunnable[] buildArray(LockingModel model) {
44          SelectiveLockRunnable[] array = new SelectiveLockRunnable[THREAD_COUNT];
45          for (int i = 0; i < THREAD_COUNT; i++) {
46              array[i] = new SelectiveLockRunnable(model);
47          }
48          return array;
49      }
50  
51  }