The caption already shows that the default lock is not the lock of the synchronization code block when the Child Thread Wai (), so the indicated lock displayed at wai time is now interpreted by the code:
public class Test {//staticboolean flag=true;public static void Main (string[] args) throws Interruptedexception {Zp z=new Zp (); Thread st=new thread (z); St.start (); for (int x=0;x<100000;x++) {if (x%5000==0) {//flag=false; Thread.Sleep (+); synchronized (Test.class)//The synchronization must be determined here, otherwise when the child thread does not discard the lock, the exception will be executed below {Test.class.notify ();}}} Static class Zp implements runnable{@Overridepublic void Run () {synchronized (Test.class) {while (true) {for (int x=0;x< 10;x++) {System.out.println ("haha ...");} try {Test.class.wait ();} catch (Interruptedexception e) {e.printstacktrace ();}}}}}
Using wait in Java requires a synchronous lock, and 2 threads must all use a synchronous block of code, otherwise the exception