中断线程方法
休眠: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()); } }