zoukankan      html  css  js  c++  java
  • 线程优先级

    package youxianji.xianchen;
    
    import java.util.MissingFormatArgumentException;
    
    /*
     * 设置线程的优先级
     * setPriority
    public final void setPriority(int newPriority)  
    参数:
    newPriority - 要为线程设定的优先级
    
    Java中 三种 优先级
      static int    MAX_PRIORITY 
              线程可以具有的最高优先级。
      static int    MIN_PRIORITY 
              线程可以具有的最低优先级。
      static int    NORM_PRIORITY 
              分配给线程的默认优先级。
     */
    //写一个类去实现runnable
    class YouXianJiDemo implements Runnable{
        //重写 run 方法
        public void run(){
            //循环 5次
            for (int i = 0; i <5; i++) {
                try {Thread.sleep(500);}
                catch(Exception e){
                    System.out.println(e);
                }
                //获取当前线程
                System.out.println(Thread.currentThread().getName()+"运行"+i);
                
            }
            
        }
    }
    public class YouXianJi {
        public static void main(String[] args) {
            //YouXianJiDemo yx =new YouXianJiDemo();
            //Thread t1 =new Thread(yx,"线程a");
            Thread t1 = new Thread(new YouXianJiDemo(),"线程a");
            Thread t2 = new Thread(new YouXianJiDemo(),"线程b");
            Thread t3 = new Thread(new YouXianJiDemo(),"线程c");
            t1.setPriority(Thread.NORM_PRIORITY);
            t2.setPriority(Thread.MAX_PRIORITY);
            t3.setPriority(Thread.MIN_PRIORITY);
            //启动线程
            t1.start();
            t2.start();
            t3.start();
            
        }
    
    }
  • 相关阅读:
    mysql cpu 占用高
    使用cron命令配置定时任务(cron jobs)
    python 获取时间
    linux 免密码登陆
    linux 查看登录日志
    shizhong
    正则(?is)
    python shell
    linux 时间设置
    java获取当前时间前一周、前一月、前一年的时间
  • 原文地址:https://www.cnblogs.com/yuanyuan2017/p/6944935.html
Copyright © 2011-2022 走看看