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 NoLockThroughput {
026
027    static int THREAD_COUNT = 3;
028    static long OVERALL_DURATION_IN_MILLIS = 2000;
029
030    public static void main(String args[]) throws InterruptedException {
031
032        ThreadedThroughputCalculator tp = new ThreadedThroughputCalculator(OVERALL_DURATION_IN_MILLIS);
033        tp.printEnvironmentInfo("NoLockThroughput");
034
035        for (int i = 0; i < 2; i++) {
036            tp.execute(buildArray(LockingModel.NOLOCK));
037        }
038
039        tp.execute(buildArray(LockingModel.NOLOCK));
040        tp.printThroughput("No lock:   ", true);
041    }
042
043    static SelectiveLockRunnable[] buildArray(LockingModel model) {
044        SelectiveLockRunnable[] array = new SelectiveLockRunnable[THREAD_COUNT];
045        for (int i = 0; i < THREAD_COUNT; i++) {
046            array[i] = new SelectiveLockRunnable(model);
047        }
048        return array;
049    }
050
051}