标签:
1、join的用法
package com.ljb.app.thread; /** * 线程调度join的使用 * @author LJB * @version 2015年3月6日 */ public class TempThread extends Thread{ public TempThread () {} public TempThread (String name) { super(name); } public void run () { for (int i = 0 ; i < 5 ; i++) { System.out.println(getName() + " " + i); } } /** * @param args */ public static void main(String[] args) { for (int i = 0 ; i < 10 ; i++) { if (i == 5) { TempThread tempThread = new TempThread(); TempThread tempThread2 = new TempThread(); try { tempThread.start(); tempThread.join(); tempThread2.start(); tempThread2.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println(Thread.currentThread().getName() + " " + i); } } }
2、运行结果
main 0
main 1
main 2
main 3
main 4
Thread-0 0
Thread-0 1
Thread-0 2
Thread-0 3
Thread-0 4
Thread-1 0
Thread-1 1
Thread-1 2
Thread-1 3
Thread-1 4
main 5
main 6
main 7
main 8
main 9
描述:主线程启动运行被线程1阻塞,第一个线程启动运行结束,第二个线程启动阻塞主线程,运行结束,主线程启动运行结束。
3、线程状态
4、线程优先级
标签:
原文地址:http://my.oschina.net/u/2320342/blog/384222