标签:read rup cpu 子线程 runnable 休眠 art new test
即使子线程休眠了,也不去抢cpu资源,等子线程做完了主线程再做;
public class Test5 { public static void main(String[] args) { MyRunnable2 r = new MyRunnable2(); Thread t = new Thread(r, "子线程"); t.start(); try { //合并线程 t.join(4000); } catch (InterruptedException e) { e.printStackTrace(); } r.run(); } } class MyRunnable2 implements Runnable { @Override public void run() { for (int i = 0; i < 30; i++) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(Thread.currentThread().getName() + ":" + i); } } }
标签:read rup cpu 子线程 runnable 休眠 art new test
原文地址:https://www.cnblogs.com/xyyou/p/12114900.html