java 第十九课

编写一个多线程处理的程序,其他线程运行10秒后,使用main的方法中断其他线程。

public class xiti_19 implements Runnable 

{

public  void run()

{

try{

System.out.println("在run()方法中—这个线程休息10秒”);

Thread.sleep(10000);

System.out.println("在run的方法中--继续运行“);

}

catch (InterruptedExceptio x){

System.out.println("在run()方法中--中断线程);

return;

{

System.out.println("在run()方法中-休息之后继续完成”);

System.out.println("在run()方法中-正常退出“);

}

public static void main(String[] args)

{

xiti_19 si = new  xiti_19();

Thread t = new Thread(si);

t.start();

try{

Thread sleep(1000);

}

catch (interruptedException x){}

System.out.println(”在main()方法中--中断其他线程“);

t.interrupt();

System.out.println("在main()方法中-退出”);

}

}

posted on 2012-09-30 08:24  汤成云  阅读(204)  评论(0)    收藏  举报

导航