通过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

posted @ 2012-03-12 15:08  JAVA教程  阅读(278)  评论(0编辑  收藏  举报