
Author: ceki Date: Sat Jun 13 23:42:34 2009 New Revision: 2289 Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/issue/NoLockingInJava.java (contents, props changed) Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/issue/LockingInJava.java Log: - Measure performance when no locking is present. - We don't need to interrupt in LockingInJava Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/issue/LockingInJava.java ============================================================================== --- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/issue/LockingInJava.java (original) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/issue/LockingInJava.java Sat Jun 13 23:42:34 2009 @@ -11,11 +11,12 @@ static int THREAD_COUNT = 5; static Object LOCK = new Object(); - static Runnable[] RUNNABLE_ARRAY = new Runnable[THREAD_COUNT]; + static LockingInJava[] RUNNABLE_ARRAY = new LockingInJava[THREAD_COUNT]; static Thread[] THREAD_ARRAY = new Thread[THREAD_COUNT]; private int counter = 0; - + private boolean done = false; + public static void main(String args[]) throws InterruptedException { printEnvironmentInfo(); execute(); @@ -47,9 +48,9 @@ Thread.sleep(10000); for (int i = THREAD_COUNT - 1; i <= 0; i--) { - THREAD_ARRAY[i].interrupt(); + RUNNABLE_ARRAY[i].done = true; } - Thread.sleep(100); // wait a moment for termination, to lazy for join ;) + } public static void printResults() { @@ -65,7 +66,9 @@ try { Thread.sleep(10); } catch (InterruptedException ex) { - break; + } + if(done) { + return; } } } Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/issue/NoLockingInJava.java ============================================================================== --- (empty file) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/issue/NoLockingInJava.java Sat Jun 13 23:42:34 2009 @@ -0,0 +1,74 @@ +package ch.qos.logback.core.issue; + +/** + * Measure throughput without any locking policy + * + * @author Joern Huxhorn + * @author Ceki Gulcu + */ +public class NoLockingInJava implements Runnable { + + static int THREAD_COUNT = 5; + static Object LOCK = new Object(); + static NoLockingInJava[] RUNNABLE_ARRAY = new NoLockingInJava[THREAD_COUNT]; + static Thread[] THREAD_ARRAY = new Thread[THREAD_COUNT]; + + private int counter = 0; + private boolean done = false; + + public static void main(String args[]) throws InterruptedException { + printEnvironmentInfo(); + execute(); + printResults(); + } + + public static void printEnvironmentInfo() { + System.out.println("java.runtime.version = " + + System.getProperty("java.runtime.version")); + System.out.println("java.vendor = " + + System.getProperty("java.vendor")); + System.out.println("java.version = " + + System.getProperty("java.version")); + System.out.println("os.name = " + + System.getProperty("os.name")); + System.out.println("os.version = " + + System.getProperty("os.version")); + } + + public static void execute() throws InterruptedException { + for (int i = 0; i < THREAD_COUNT; i++) { + RUNNABLE_ARRAY[i] = new NoLockingInJava(); + THREAD_ARRAY[i] = new Thread(RUNNABLE_ARRAY[i]); + } + for (Thread t : THREAD_ARRAY) { + t.start(); + } + // let the threads run for a while + Thread.sleep(10000); + + for (int i = THREAD_COUNT - 1; i <= 0; i--) { + RUNNABLE_ARRAY[i].done = true; + } + + } + + public static void printResults() { + for (int i = 0; i < RUNNABLE_ARRAY.length; i++) { + System.out.println("runnable[" + i + "]: " + RUNNABLE_ARRAY[i]); + } + } + + public void run() { + for (;;) { + counter++; + if (done) { + return; + } + } + } + + public String toString() { + return "counter=" + counter; + } + +}