JAVA_Thread_daemon

package com.kk.thread;
/*
* java使用抢占式调度模型
*/
public class ThreadTest {
public static void main(String[] args) {
MyThread myThread=new MyThread();//main线程的时间片完后,才执行Mythread的时间片
myThread.setDaemon(true);
myThread.start();
myThread.setPriority(Thread.MAX_PRIORITY);//设置线程的执行等级,等级高执行时间片越长
int index=0;
while(true){
++index;
if(index==400)break;//main线程终止,其它的线程也终止
System.out.println(Thread.currentThread().getName());
}
}
}

class MyThread extends Thread{
public void run() {
while(true){
System.out.println(getName());
yield(); //停止此次执行
}
}
}
原文地址:https://www.cnblogs.com/BigIdiot/p/2290466.html