zoukankan      html  css  js  c++  java
  • java:线程的简单控制方法

    中断线程方法

    休眠:sleep();

    主动让出cpu:yield();

    设置线程优先级:

    取值:getPriority();

    设置:setPriority(..);

    MAX_PRIORITY最大优先级

    MIN_PRIORITY最小优先级

    级别越大,运行概率越大

    class RunableImp implements Runnable
    {
        public void run(){
        
        }
    }
    class Test
    {
        public static void main(String args[]){
            RunableImp run = new RunableImp();
            Thread t =new Thread(run);
            //休眠1000毫秒
            try{t.sleep(1000);
            }
            catch(Exception e){
                System.out.println(e);
            }
            //获取优先级
            System.out.println(t.getPriority());
            //设置最大优先级
            t.setPriority(t.MAX_PRIORITY);
            System.out.println(t.getPriority());
        }
    }
  • 相关阅读:

    (luogu)[模板]最长公共子序列
    表达式的值
    邮票面值设计
    尼克的任务
    HISTOGRA
    消防局的设立
    青蛙的约会
    产生数
    奇怪的电梯
  • 原文地址:https://www.cnblogs.com/tinyphp/p/3758655.html
Copyright © 2011-2022 走看看