public class Thread5 {public static void main(String[] args) {SubThread subThread = new SubThread();subThread.start();try {//主线程睡眠2秒,确保子线程处于wait状态Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}subThread.interrupt();}private static final Object lock = new Object();static class SubThread extends Thread {@Overridepublic void run() {synchronized (lock) {System.out.println("begin wait");try {lock.wait();System.out.println("end wait");} catch (InterruptedException e) {System.out.println("等待被中断");e.printStackTrace();}}}}
}