9 public synchronized void add(long value){
13 public synchronized long getCounter() {
18 public class CounterThread extends Thread{
21 protected Counter counter;
23 public CounterThread(String name, Counter counter){
25 this.counter = counter;
29 for(int i=0; i<10; i++){
30 System.printString(this.name);
32 System.printString(" " + counter.getCounter() + "\n");
37 public class SynchonizedTest {
38 public SynchonizedTest() {
41 public static void main(String[] args){
42 Counter counter = new Counter();
43 Thread threadA = new CounterThread("A\n",counter);
44 Thread threadB = new CounterThread("B\n",counter);
50 /*public static void main(String[] args){
51 Counter counterA = new Counter();
52 Counter counterB = new Counter();
53 Thread threadA = new CounterThread("A\n",counterA);
54 Thread threadB = new CounterThread("B\n",counterB);