首页 > 代码库 > java 线程的优先级

java 线程的优先级

 

//线程的优先级//线程1class xc1 implements Runnable{    public void run(){        for(int i=0;i<20;i++){            System.out.println("线程1___"+i);        }    }}//线程2class xc2 implements Runnable{  public void run(){      for(int i=0;i<20;i++){          System.out.println("线程2___"+i);      }  }}public class Index{    public static void main(String[] args){                //线程1        xc1 xc1 = new xc1();        Thread xc1_Thread = new Thread(xc1);        //线程优先级        //setPriority 方法,是设置优先级        //Thread.NORM_PRIORITY 当前的优先级,默认为5        xc1_Thread.setPriority(Thread.NORM_PRIORITY+3);                xc1_Thread.start();    //执行线程                //线程2        xc2 xc2 = new xc2();        Thread xc2_Thread = new Thread(xc2);        xc2_Thread.start();                            }}

 

java 线程的优先级