//线程的让步 // //线程 class xc1 implements Runnable{ public void run(){ for(int i=1;i<=30;i++){ System.out.println(Thread.currentThread().getName()+"线程___"+i); if(i%5==0){ System.out.println("=====开始让步======"); //线程的让步 Thread.yield(); } } } } public class Index{ public static void main(String[] args){ //线程1 xc1 xc1 = new xc1(); Thread xc1_Thread = new Thread(xc1); xc1_Thread.start(); //执行线程 //线程2 xc1 xc2 = new xc1(); Thread xc2_Thread = new Thread(xc2); xc2_Thread.start(); //执行线程 } }