1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.issue;
15
16 import ch.qos.logback.core.contention.RunnableWithCounterAndDone;
17 import ch.qos.logback.core.contention.ThreadedThroughputCalculator;
18 import ch.qos.logback.core.issue.SelectiveLockRunnable.LockingModel;
19
20
21
22
23
24
25
26 public class LockThroughput {
27
28 static int THREAD_COUNT = 10;
29 static long OVERALL_DURATION_IN_MILLIS = 5000;
30
31 public static void main(String args[]) throws InterruptedException {
32
33 ThreadedThroughputCalculator tp = new ThreadedThroughputCalculator(OVERALL_DURATION_IN_MILLIS);
34 tp.printEnvironmentInfo("LockThroughput");
35
36 for (int i = 0; i < 2; i++) {
37 tp.execute(buildArray(LockingModel.SYNC));
38 tp.execute(buildArray(LockingModel.UNFAIR));
39 tp.execute(buildArray(LockingModel.FAIR));
40 }
41
42
43 RunnableWithCounterAndDone[] runnableArraySync = buildArray(LockingModel.SYNC);
44 tp.execute(runnableArraySync);
45 tp.printThroughput(runnableArraySync, "Sync: ");
46
47
48 RunnableWithCounterAndDone[] runnableArrayUnfair = buildArray(LockingModel.UNFAIR);
49 tp.execute(runnableArrayUnfair);
50 tp.printThroughput(runnableArrayUnfair, "Unfair: ");
51
52 RunnableWithCounterAndDone[] runnableArrayFair = buildArray(LockingModel.FAIR);
53 tp.execute(runnableArrayFair);
54 tp.printThroughput(runnableArrayFair, "Fair: ");
55 }
56
57 static SelectiveLockRunnable[] buildArray(LockingModel model) {
58 SelectiveLockRunnable[] array = new SelectiveLockRunnable[THREAD_COUNT];
59 for (int i = 0; i < THREAD_COUNT; i++) {
60 array[i] = new SelectiveLockRunnable(model);
61 }
62 return array;
63 }
64
65 }