package com.test.docxml; /** Thread交互及interrupt示例 * 线程模拟:一个在睡觉,一个在敲墙,敲墙完成之后,把睡觉的吵醒了。 */ public class ThreadTest { public static void main(String[] args) throws Exception{ Thread t1 = new Thread(){ @Override public void run() { for (int i = 0; i < 8; i++) { try { System.out.println(Thread.currentThread().getName() + "ZZZZZZZzzzzz"); Thread.sleep(1000l); }catch (InterruptedException e) { System.out.println("ZZZzzz exception"); e.printStackTrace(); break; } } } }; Thread t2 = new Thread(){ @Override public void run() { for (int i = 0; i < 5; i++) { try { System.out.println(Thread.currentThread().getName() + "KuangKuangKuang"); Thread.sleep(1000); }catch (InterruptedException e) { e.printStackTrace(); } } t1.interrupt(); //人工打断 } }; t1.start(); t2.start(); } }