找到工作再改名1

找到工作再改名1

public class Util {

    public void run(){
        Object ob = new Object();

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (ob){
                    try {
                        for (int i = 0 ;i < 100; i=i+2){
                            ob.notify();
                            System.out.println("num--"+ i);
//                            Log.d("num--", "" + i); //偶数
                            ob.wait();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (ob){
                    try {
                        for (int i = 1 ;i < 100; i=i+2){
                            ob.notify();
                            System.out.println("num------"+ i);
//                            Log.d("num------", "" + i);  //奇数
                            ob.wait();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    public static void main(String[] args) {
        Util u=new Util();
        u.run();
    }
}
05-03 09:15