From f8e5b35d8e8c08c04bcdc9aeaf2c3c7c8e532f76 Mon Sep 17 00:00:00 2001 From: jzhou Date: Thu, 14 Oct 2010 18:06:29 +0000 Subject: [PATCH] Add test for reentrant feature of the synchronized blocks --- Robust/src/Tests/MGC/SynchonizedTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Robust/src/Tests/MGC/SynchonizedTest.java b/Robust/src/Tests/MGC/SynchonizedTest.java index bb63fb18..9b5528bc 100644 --- a/Robust/src/Tests/MGC/SynchonizedTest.java +++ b/Robust/src/Tests/MGC/SynchonizedTest.java @@ -8,7 +8,6 @@ public class Counter{ public synchronized void add(long value){ this.count += value; - System.printString(" " + this.count + "\n"); } public synchronized long getCounter() { @@ -30,6 +29,7 @@ public class CounterThread extends Thread{ for(int i=0; i<10; i++){ System.printString(this.name); counter.add(i); + System.printString(" " + counter.getCounter() + "\n"); } } } @@ -46,4 +46,14 @@ public class SynchonizedTest { threadA.start(); threadB.start(); } + + /*public static void main(String[] args){ + Counter counterA = new Counter(); + Counter counterB = new Counter(); + Thread threadA = new CounterThread("A\n",counterA); + Thread threadB = new CounterThread("B\n",counterB); + + threadA.start(); + threadB.start(); + }*/ } -- 2.34.1