正在加载图片...
Java多线程机制 历些毛子科枚大多 XIDIAN UNIVERSITY ■ 方法一(继承Thread) class testThread extends Thread public testThread(String str){ super(str);∥调用父类的构造方法为线程像命名 关键字 注释 3 public void run({ for (int i=0;i<3;i++){ System.out.println(getName0+"在运行"); try sleep(1000);∥用休眠1000毫秒来区分哪个线程在运行 System.out.println(getName0+"在休眠"); catch(InterruptedException e){} }//try-catch ends System.out.println(getName0+"已结束"); 1}//run ends }//class ends 9Java多线程机制 class testThread extends Thread { public testThread(String str) { super(str); //调用父类的构造方法为线程对象命名 } public void run() { for (int i=0; i<3; i++) { System.out.println(getName()+"在运行"); try { sleep(1000); // 用休眠1000毫秒来区分哪个线程在运行 System.out.println(getName()+"在休眠"); } catch (InterruptedException e) {} } //try-catch ends System.out.println(getName()+"已结束"); } //run ends } //class ends 9 ◼ 方法一(继承Thread) 关键字 注释
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有