java多线程快速入门(八)
设置线程优先级:join()
package com.cppdy; class MyThreadA extends Thread{ MyThreadB b; public MyThreadA(MyThreadB b) { this.b=b; } @Override public void run() { try { b.join(); sleep(1000); } catch (Exception e) { } System.out.println("A子线程执行"); } } class MyThreadB extends Thread{ @Override public void run() { try { sleep(1000); } catch (Exception e) { } System.out.println("B子线程执行"); } } public class ThreadDemo4 { public static void main(String[] args) throws Exception{ MyThreadB mt2 = new MyThreadB(); MyThreadA mt1 = new MyThreadA(mt2); mt1.start(); mt2.start(); mt1.join(); System.out.println("主线程执行"); } }