public class TestPriority {
public static void main(String[] args) {
// main的线程优先级
System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());
MyPriority myPriority = new MyPriority();
Thread t = new Thread(myPriority,"a");
Thread t2 = new Thread(myPriority,"b");
t.start();
t2.setPriority(10);// 设置优先级
t2.start();
}
}
class MyPriority implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());
}
}
public class TestDaemon {
public static void main(String[] args) {
Lucky lucky = new Lucky();
Youlucky you = new Youlucky();
Thread godt = new Thread(lucky);
godt.setDaemon(true);// 默认是false,有true代表是守护进程
godt.start(); // 守护线程
new Thread(you).start();// 用户线程
}
}
class Lucky implements Runnable{
@Override
public void run() {
while(true){
System.out.println("运气一直在");
}
}
}
class Youlucky implements Runnable{
@Override
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println("运气好");
}
System.out.println("================================See You!=======================================");
}
}
原文:https://www.cnblogs.com/jie7/p/15306025.html