ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
让步 ~~~ package thread.a4; public class Test { public static void main(String[] args) { Xc6 xc6 = new Xc6(); Thread aa = new Thread(xc6); Thread bb = new Thread(xc6); aa.setName("线程一"); bb.setName("线程二"); aa.start(); bb.start(); } } class Xc6 implements Runnable { public void run() { for(int i=1;i<=30;i++) { System.out.println(Thread.currentThread().getName()+": "+i); if(i%5==0) { Thread.yield(); } } } } ~~~ 阻塞 ~~~ package thread.a4; public class Test1 { public static void main(String args[]) { Xc7 xc7=new Xc7(); Thread dd = new Thread(xc7); dd.start(); try{ dd.join(); //阻塞时将当前线程暂停,直至调用join函数所对应的线程执行完毕,才继续执行程序。 } catch(Exception e) { } for(int i=0;i<15;i++){ System.out.println("主线程:" + i); } } } class Xc7 implements Runnable { public void run() { for(int i=0;i<10;i++) { System.out.println("子线程: " + i); } } } ~~~ ![](https://box.kancloud.cn/4b85d7a51382e970e139dfde22158161_244x299.png)