JAVA SE high-level language study notes -03.Java -05- abnormal and multithreading - Section 4 waiting wake-up mechanism

1_7_4_01_ thread state .avi Overview

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
1_7_4_02_ wait wake Case .avi

Here Insert Picture Description
1_7_4_03_ wait wake Case code for .avi

Here Insert Picture Description
Here Insert Picture Description

public class DemoWaitAndNotify {
    public static void main(String[] args) {
        Object object = new Object();
        new Thread() {
            @Override
            public void run() {
                while (true) {
                    synchronized (object) {
                        System.out.println("告诉老板要的饺子和数量");
                        try {
                            object.wait();
                        } catch (InterruptedException i) {
                            i.printStackTrace();
                        }
                        System.out.println("包子已经做好了,开吃");
                        System.out.println("------------------------------------------------------------------->>>>");
                    }
                }
            }
        }.start();
        new  Thread() {
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (object) {
                        System.out.println("老板5秒后做好包子,告诉消费者做好包子了");
                        object.notify();
                    }
                }
            }
        }.start();
    }
}

1_7_4_04_Object wait parameterized class and method notif.avi

Here Insert Picture Description

Inter-thread communication 1_7_4_05_ .avi

Waiting and wake-up mechanism

Here Insert Picture Description
1_7_4_06_ wait wake-up mechanism outlined .avi

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
1_7_4_08_ wait wake-up mechanism code that implements _ buns class & package .avi

Here Insert Picture Description
1_7_4_09_ wait wake-up mechanism code that implements _ food goods class & test .avi

Here Insert Picture Description
Here Insert Picture Description
Baozi Pu
Here Insert Picture Description

Published 168 original articles · won praise 39 · views 110 000 +

Guess you like

Origin blog.csdn.net/u010481276/article/details/104982071