1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| package 多线程;
public class MyThreadDemo {
public static void main(String[] args) { // TODO Auto-generated method stub MyThread mt=new MyThread("1"); MyThread mt2=new MyThread("2"); // mt.setName("1"); // mt2.setName("2"); //设置主线程 Thread.currentThread().setName("3"); for(int i=0;i<10;i++) { System.out.println(Thread.currentThread().getName()+" "+i); } //设置为守护线程,当jvn里面全是守护线程时结束。 mt2.setDaemon(true); mt.setDaemon(true); mt2.setPriority(1); mt.setPriority(1); mt.start(); // try { // mt.join();//等待mt这个线程的死亡,其余线程等待这个线程结束 // } catch (InterruptedException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } mt2.start(); System.out.println(mt.getPriority());//返回此线程的优先级 //最高10,最低1 System.out.println(mt.currentThread().getName()); }
}
|