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.ThreadedThroughputCalculator;
17 import ch.qos.logback.core.issue.SelectiveLockRunnable.LockingModel;
18
19
20
21
22
23
24
25 public class LockThroughput {
26
27 static int THREAD_COUNT = 10;
28 static long OVERALL_DURATION_IN_MILLIS = 5000;
29
30 public static void main(String args[]) throws InterruptedException {
31
32 ThreadedThroughputCalculator tp = new ThreadedThroughputCalculator(OVERALL_DURATION_IN_MILLIS);
33 tp.printEnvironmentInfo("LockThroughput");
34
35 for (int i = 0; i < 2; i++) {
36 tp.execute(buildArray(LockingModel.SYNC));
37 tp.execute(buildArray(LockingModel.UNFAIR));
38 tp.execute(buildArray(LockingModel.FAIR));
39 }
40
41 tp.execute(buildArray(LockingModel.SYNC));
42 tp.printThroughput("Sync: ");
43
44 tp.execute(buildArray(LockingModel.UNFAIR));
45 tp.printThroughput("Unfair: ");
46
47 tp.execute(buildArray(LockingModel.FAIR));
48 tp.printThroughput("Fair: ");
49 }
50
51 static SelectiveLockRunnable[] buildArray(LockingModel model) {
52 SelectiveLockRunnable[] array = new SelectiveLockRunnable[THREAD_COUNT];
53 for (int i = 0; i < THREAD_COUNT; i++) {
54 array[i] = new SelectiveLockRunnable(model);
55 }
56 return array;
57 }
58
59 }