Wait12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152package 锁wait;/** * @Author: 赵博雅 * @Date: 2020/6/10 0:16 */public class wait { public static void main(String[] args) { waitTest waitTist = new waitTest("线程1"); synchronized (waitTist){ String threadName = Thread.currentThread().getName(); System.out.println(threadName + " 启动..."); waitTist.start(); try { waitTist.wait(); //主线程进入等待状态 System.out.println(threadName + " 接着运行..."); } catch (InterruptedException e) { e.printStackTrace(); } } }}class waitTest extends Thread { public waitTest(String name) { super(name); } public void run() { synchronized (this){ String threadName = Thread.currentThread().getName(); System.out.println(threadName + " 启动..."); try { System.out.println(threadName + " 工作中..."); Thread.sleep(5000); System.out.println(threadName + " 完成..."); this.notify(); //使其他线程进入就绪状态 } catch (Exception e) { e.printStackTrace(); } } }} “wait”的运行结果