package threadtest1;public class threadtest1 {
    private int j;
    Thread thread = new Thread();
    private synchronized void inc() {
        j++;
        System.out.println(thread.currentThread().getName() + "-inc:" + j);
    }    private synchronized void dec() {
        j--;
        System.out.println(thread.currentThread().getName() + "-dec:" + j);
    }    class inc implements Runnable {
        public void run() {
            for (int i = 0; i < 100; i++) {
                inc();
            }
        }
    }
    class dec implements Runnable {
        public void run() {
            for (int i = 0; i < 100; i++) {
                dec();
            }
        }
    }    public static void main(String[] args) {
        threadtest1 tt = new threadtest1();
        inc inc = tt.new inc();
        dec dec = tt.new dec();
        for (int i = 0; i < 2; i++) {
            Thread t = new Thread(inc);
            t.start();
            t = new Thread(dec);
            t.start();
        }    }
}