From 1f5c6d110c6177a64125db8f2feb20d47aec3037 Mon Sep 17 00:00:00 2001 From: jzhou Date: Thu, 14 Oct 2010 17:59:34 +0000 Subject: [PATCH] Add Test for multicore gc version w/o tasks --- Robust/src/Tests/MGC/SynchonizedTest.java | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Robust/src/Tests/MGC/SynchonizedTest.java diff --git a/Robust/src/Tests/MGC/SynchonizedTest.java b/Robust/src/Tests/MGC/SynchonizedTest.java new file mode 100644 index 00000000..bb63fb18 --- /dev/null +++ b/Robust/src/Tests/MGC/SynchonizedTest.java @@ -0,0 +1,49 @@ +public class Counter{ + + long count; + + public Counter() { + this.count = 0; + } + + public synchronized void add(long value){ + this.count += value; + System.printString(" " + this.count + "\n"); + } + + public synchronized long getCounter() { + return this.count; + } +} + +public class CounterThread extends Thread{ + + String name; + protected Counter counter; + + public CounterThread(String name, Counter counter){ + this.name = name; + this.counter = counter; + } + + public void run() { + for(int i=0; i<10; i++){ + System.printString(this.name); + counter.add(i); + } + } +} + +public class SynchonizedTest { + public SynchonizedTest() { + } + + public static void main(String[] args){ + Counter counter = new Counter(); + Thread threadA = new CounterThread("A\n",counter); + Thread threadB = new CounterThread("B\n",counter); + + threadA.start(); + threadB.start(); + } +} -- 2.34.1