通过IO中断线程
class TestThread { public static void main(String[] args) { Data data = new Data(); //创建四个线程 Thread thadd1 = new ThreadAdd(data, "thadd1"); Thread thadd2 = new ThreadAdd(data, "thadd2"); Thread thsub1 = new ThreadSub(data, "thsub1"); Thread thsub2 = new ThreadSub(data, "thsub2"); //启动四个线程 thadd1.start(); try { //等待用户从控制台输入数据 int k = System.in.read(); } catch (Exception e) { e.printStackTrace(); } System.out.println("io 已经执行完毕"); thadd2.start(); thsub1.start(); thsub2.start(); } }
运行的结果如图5:
http://www.5itjob.com
http://www.rjpx.net