001package observer.two;
002public class Main {
003        public static void main(String[] argv) {
004                Int c = new Int();
005                Runnable r1 = new M(c);
006                Runnable r2 = new N(c);
007                for (int i=0; i<10000; i++) {
008                        r1.run();
009                        r2.run();
010                }
011        }
012}
013class Int {
014        private int v;
015        public int get() { return v; }
016        public void inc() { v++; }
017        public void dec() { v--; }
018}
019class M implements Runnable {
020        private int numOps;
021        private Int c;
022        public M(Int c) { this.c = c; }
023        public void run() {
024                c.inc(); System.out.println (++numOps);
025                c.inc(); System.out.println (++numOps);
026                c.dec(); System.out.println (++numOps);
027        }
028}
029class N implements Runnable {
030        private Int c;
031        public N(Int c) { this.c = c; }
032        public void run() {
033                for (int i=0; i<50; i++) {
034                        if (i%3==0) {
035                                c.dec(); /*??*/
036                        } else {
037                                c.inc(); /*??*/
038                        }
039                }
040        }
041}