61java多线程常用操作方法(线程优先级)

92 阅读1分钟

多线程常用操作方法(线程优先级)

一、优先级的概述

设置优先级:public final void sePriority(int newI)

取得优先级:pubic final int getPriority()。

对于优先级的设置的内容可以通过 Thread 类的几个常量来决定:

最高优先级:public static final int MAX_PRIORITY,   10 ;

中等优先级:public static final int NORM_PRIORITY ,   5 ;

最低优先级:public static final int MIN_PRIORITY,    1 ;

二、设置优先级的范例


Public class TestDemo {

Public static void main (String[ ] args )throws Exception{

My Thread mt = new MyThread();

Thread t1 New Thread(mt).start(); //通过线路调用

Thread t2 New Thread(mt).start(); //通过线程调用

Thread t3 New Thread(mt).start(); //通过线程调用

t1.start();

t2.start();

t3.start();

}

}