File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ public void method() {
3939class Caller implements Runnable {
4040 private Guarded g ;
4141 public Caller (Guarded g ) { this .g = g ; }
42+ private AtomicLong successfulCalls =
43+ new AtomicLong ();
4244 private AtomicBoolean stop =
4345 new AtomicBoolean (false );
4446 class Stop extends TimerTask {
@@ -48,8 +50,12 @@ class Stop extends TimerTask {
4850 @ Override
4951 public void run () {
5052 new Timer ().schedule (new Stop (), 2500 );
51- while (!stop .get ())
53+ while (!stop .get ()) {
5254 g .method ();
55+ successfulCalls .getAndIncrement ();
56+ }
57+ System .out .println (
58+ "-> " + successfulCalls .get ());
5359 }
5460}
5561
@@ -72,6 +78,14 @@ public static void main(String[] args) {
7278 }
7379}
7480/* Output:
75- CriticalSection: 972
76- SynchronizedMethod: 247
81+ -> 152
82+ -> 152
83+ -> 153
84+ -> 153
85+ CriticalSection: 610
86+ -> 44
87+ -> 28
88+ -> 62
89+ -> 24
90+ SynchronizedMethod: 158
7791*/
You can’t perform that action at this time.
0 commit comments