3.线程基本信息
Thread.currentThread():static 当前线程
方法: setName() getName() isAlive()
优先级: 概率 非绝对的优先级
t1.setPriority(Thread.MAX_PRIORITY); t1.getPriority();
* MAX_PRIORITY 10
* NORM_PRIORITY 5
* MIN_PRIORITY 1
/**
* 描述:优先级 概率 非绝对的优先级
* MAX_PRIORITY 10
* MIN_PRIORITY 1
* NORM_PRIORITY 5
* @author cookie
*/
public class InfoDemo02 {
public static void main(String[] args) throws InterruptedException {
MyThread it1= new MyThread();
Thread p1 = new Thread(it1,"挨踢1");
MyThread it2= new MyThread();
Thread p2 = new Thread(it2,"挨踢2");
p1.setPriority(Thread.MAX_PRIORITY);//设置优先级
p2.setPriority(Thread.MIN_PRIORITY);//设置优先级
p1.start();
p2.start();
Thread.sleep(100);
it1.stop();
it2.stop();
}
}
class MyThread implements Runnable {
private int num = 0;
private boolean flag = true;
@Override
public void run() {
while(flag){
System.out.println(Thread.currentThread().getName()+"--->"+ num++);
}
}
public void stop(){
this.flag = false;
}
}

浙公网安备 33010602011771号