001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.issue; 015 016import ch.qos.logback.core.contention.ThreadedThroughputCalculator; 017import ch.qos.logback.core.issue.SelectiveLockRunnable.LockingModel; 018 019/** 020 * Short sample code testing the throughput of a fair lock. 021 * 022 * @author Joern Huxhorn 023 * @author Ceki Gulcu 024 */ 025public class LockThroughput { 026 027 static int THREAD_COUNT = 10; 028 static long OVERALL_DURATION_IN_MILLIS = 5000; 029 030 public static void main(String args[]) throws InterruptedException { 031 032 ThreadedThroughputCalculator tp = new ThreadedThroughputCalculator(OVERALL_DURATION_IN_MILLIS); 033 tp.printEnvironmentInfo("LockThroughput"); 034 035 for (int i = 0; i < 2; i++) { 036 tp.execute(buildArray(LockingModel.SYNC)); 037 tp.execute(buildArray(LockingModel.UNFAIR)); 038 tp.execute(buildArray(LockingModel.FAIR)); 039 } 040 041 tp.execute(buildArray(LockingModel.SYNC)); 042 tp.printThroughput("Sync: "); 043 044 tp.execute(buildArray(LockingModel.UNFAIR)); 045 tp.printThroughput("Unfair: "); 046 047 tp.execute(buildArray(LockingModel.FAIR)); 048 tp.printThroughput("Fair: "); 049 } 050 051 static SelectiveLockRunnable[] buildArray(LockingModel model) { 052 SelectiveLockRunnable[] array = new SelectiveLockRunnable[THREAD_COUNT]; 053 for (int i = 0; i < THREAD_COUNT; i++) { 054 array[i] = new SelectiveLockRunnable(model); 055 } 056 return array; 057 } 058 059}