Skip to content

Commit 3561018

Browse files
committed
finishing
1 parent a179863 commit 3561018

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

lowlevel/SynchronizedComparison.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public void method() {
3939
class 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
*/

0 commit comments

Comments
 (0)