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()); } }
本文来自博客园,作者:tinyphp,转载请注明原文链接:https://www.cnblogs.com/tinyphp/p/3758655.html
向着星辰与深渊,博客园加油

浙公网安备 33010602011771号