static void yield()
暂停当前正在执行的线程对象,并执行其他线程。
eg:
class Join implements Runnable { public void run() { for(int x=0;x<60;x++) System.out.println(Thread.currentThread().toString()+"......."+x); Thread.yield();//释放当前正在执行的线程的执行权,稍微减缓线程执行的频率。 } }
class YieldDemo { public static void main(String[] args)throws InterruptedException { Join j = new Join(); Thread t1 = new Thread(j); Thread t2 = new Thread(j); t1.start(); t2.start(); for(int x=0;x<80;x++){} } }
|