且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

多线程常用操作方法(线程优先级)|学习笔记

更新时间:2022-08-20 13:22:44

开发者学堂课程【【名师课堂】Java 高级开发多线程常用操作方法(线程优先级)】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/372/detail/4561


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


目录:

一、优先级概述

二、设置优先级的范例

 

一、优先级的概述

设置优先级: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();

}

}