zoukankan      html  css  js  c++  java
  • 56、设置线程优先级

    设置线程优先级

    可以通过使用Thread类中的setPriority方法设置线程的优先级。
    setPriority()方法接收一个int类型的参数,通过这个参数可以指定线程的优先级,取值范围是整数1~10,优先级随着数字的增大而增强。
    在Thread类中封装了三个int类型的数字:
    优先级最低:public final static int MIN_PRIORITY = 1;
    优先级居中:public final static int NORM_PRIORITY = 5;
    优先级最高:public final static int MAX_PRIORITY = 10;

    package com.sutaoyu.Thread;
    
    public class test_8 {
        public static void main(String[] args) {
            Thread t1 = new Thread() {
                public void run(){
                    for(int i = 0;i < 100;i++) {
                        System.out.println(i + ".monkey");
                    }
                }
            };
            
            Thread t2 = new Thread() {
                public void run(){
                    for(int i = 0;i < 100;i++) {
                        System.out.println(i + ".1024");
                    }
                }
            };
            
            //设置线程优先级
    //        t1.setPriority(2);
    //        t2.setPriority(8);
            
            t1.setPriority(Thread.MAX_PRIORITY);
            t2.setPriority(Thread.MIN_PRIORITY);
            
            t1.start();
            t2.start();
        }
    }
  • 相关阅读:
    知多少进程?
    提高.NET应用性能
    战术设计DDD
    win7下exe文件设置为开机启动
    CQRS项目
    DDD总览
    ML.Net Model Builder
    MySQL主主复制搭建教程收集(待实践)
    MySQL主从复制搭建教程收集(待实践)
    MySQL集群方案收集
  • 原文地址:https://www.cnblogs.com/zhuifeng-mayi/p/10154134.html
Copyright © 2011-2022 走看看