Java 創(chuàng)建線程示例
//創(chuàng)建線程示例
public class ThreadPriority implements Runnable {
@Override
public void run() {
for(int i = 0;i<5;i++) {
System.out.println(Thread.current().getName()+"輸出"+i);
}
}
public static void main(String[] args) {
Thread maxPriority = new Thread(new ThreadPriority(),"高優(yōu)先級(jí)線程");
Thread minPriority = new Thread(new ThreadPriority(), "低優(yōu)先級(jí)線程");
maxPriority.setPriority(Thread.MAX_PRIORITY);//高優(yōu)先級(jí)線程
minPriority.setPriority(Thread.MAX_PRIORITY); //低優(yōu)先級(jí)線程
maxPriority. start();
minPriority.start();
}
}
點(diǎn)擊加載更多評(píng)論>>