1.繼承自 Theard類 實(shí)現(xiàn) run方法 開啟現(xiàn)成 start方法開啟線程咪啡。
2.實(shí)現(xiàn)Runnable接口 實(shí)現(xiàn) run方法 實(shí)例化 Theard并把自己的類加入 start方法開啟線程。
`
mytherad ri = new mytherad();
run2 r =new run2();
Thread th1 = new Thread(ri);
Thread th2 = new Thread(r);
th1.setPriority(Thread.MAX_PRIORITY);
th2.setPriority(Thread.MIN_PRIORITY);// 優(yōu)先級(jí)1 到10
th1.start();
th2.start();
Thread.sleep(100);
Thread.yield(); // 釋放資源 但仍參與資源競(jìng)爭(zhēng)
Thread.join;// 加賽
`