日期:2014-05-20 浏览次数:20682 次
public class setPriority{ public static void main(String args[]){ MyThread3 t1 = new MyThread3("t1"); MyThread3 t2 = new MyThread3("t2"); t1.start(); t2.start(); Thread t3 = new Thread(new MyThread4());//以MyThread4类的实例作为参数 t3.start(); } } class MyThread3 extends Thread{ MyThread3(String s){ super(s); } public void run(){ for (int i=1;i <100;i++){ System.out.println(getName()+":"+i); if(i%10==0){ yield(); } } } } class MyThread4 implements Runnable{ //实现Runnable接口 public void run(){ //some codes } }