/*
join:
當A線程執行到了B線程的.join()方法時,A就會等待。等B線程都執行完,A才會執行。
join可以用來臨時加入線程執行。
1.線程使用join方法,主線程就停下,等它執行完,那么如果該線程凍結了,主線程就掛了,這也是為什么線程要拋異常的原因
2.當兩個或以上線程開啟了,這個A線程才使用join方法,那么主線程還是停下,這幾個個線程交替進行,直到A執行完,主線程才復活
*/
/*
1.tostring(),方法,獲取線程具體的名字,優先級
2.優先級代表搶資源的頻率
3.java中設置有1 - 5 - 10這三個級別,因為是固定值,所以用字母大寫表示
4.跟設置后台線程一樣,都屬於線程的函數,由線程對象直接調用 r.setPriority(Thread.字母級別)
5.匿名內部類?是多線程的關鍵,必須掌握
*/
class Demo implements Runnable
{
public void run()
{
for(int x=0; x<70; x++)
{
System.out.println(Thread.currentThread().toString()+"....."+x);
Thread.yield();
}
}
}
class JoinDemo
{
public static void main(String[] args) throws Exception
{
Demo d = new Demo();
Thread t1 = new Thread(d);
Thread t2 = new Thread(d);
t1.start();
//t1.setPriority(Thread.MAX_PRIORITY);
t2.start();
//t1.join();
for(int x=0; x<80; x++)
{
//System.out.println("main....."+x);
}
System.out.println("over");
}
}
