setpriority_Java Thread类的最终void setPriority(int priority)方法(带示例)
setpriority
线程类最终void setPriority(int priority) (Thread Class final void setPriority(int priority))
This method is available in package java.lang.Thread.setPriority(int priority).
软件包java.lang.Thread.setPriority(int priority)中提供了此方法。
This method is used to set the priority of this thread.
此方法用于设置此线程的优先级。
This method is not static so this method is accessible with Thread class object it is not accessible with the class name.
此方法不是静态的,因此该方法可通过Thread类对象访问,而无法通过类名称访问。
This method is final so we can't override this method in our program.
此方法是最终方法,因此我们无法在程序中覆盖此方法。
The return type of this method is void so it does not return anything.
此方法的返回类型为void,因此它不返回任何内容。
This method does not raise any exception.
此方法不会引发任何异常。
We need to notice that if we don't assign any priority explicitly the default priority of this thread is 5.
我们需要注意的是,如果我们未明确分配任何优先级,则此线程的默认优先级为5。
Priority range will lie between 1 and 10 and 1 is the min_priority and 10 is the max_priority of a thread.
优先级范围在1到10之间,其中1是线程的min_priority ,而10是max_priority 。
Syntax:
句法:
final void setPriority(int priority){
}
Parameter(s):
参数:
We pass only one object as a parameter in the method of the Thread and the parameter is the priority of this thread too.
我们仅在Thread方法中传递一个对象作为参数,该参数也是该线程的优先级。
Return value:
返回值:
The return type of this method is void, it does not return anything.
此方法的返回类型为void ,它不返回任何内容。
Java程序演示setPriority()方法的示例 (Java program to demonstrate example of setPriority() method)
/* We will use Thread class methods so we are importing
the package but it is not mandate because
it is imported by default
*/
import java.lang.Thread;
class SetThreadPriority extends Thread {// Override run() of Thread class
public void run() {System.out.println("Thread Name : " + Thread.currentThread().getName());
System.out.println("Current thread priority is : " + Thread.currentThread().getPriority());
// By using setPriority() method is used to change
// the priority of this thread
Thread.currentThread().setPriority(6);
System.out.println("New thread priority is : " + Thread.currentThread().getPriority());
}
public static void main(String[] args) {// Creating an object of SetThreadPriority class
SetThreadPriority st_priority = new SetThreadPriority();
// We are setting the name of the thread GetThreadPriority
st_priority.setName("SetThreadPriority");
// Calling start() method with SetThreadPriority class
// object of Thread class
st_priority.start();
}
}
Output
输出量
E:\Programs>javac SetThreadPriority.java
E:\Programs>java SetThreadPriority
Thread Name : SetThreadPriority
Current thread priority is : 5
New thread priority is : 6
翻译自: https://www.includehelp.com/java/thread-class-final-void-setpriority-int-priority-method-with-example.aspx
setpriority
setpriority_Java Thread类的最终void setPriority(int priority)方法(带示例)相关推荐
- Java Thread类的最终void join()方法与示例
线程类最终void join() (Thread Class final void join()) This method is available in package java.lang.Thre ...
- dumpstack_Java Thread类的静态void dumpStack()方法(带示例)
dumpstack 线程类静态void dumpStack() (Thread Class static void dumpStack()) This method is available in p ...
- C# “Thread类Suspend()与Resume()已过时” 解决方法(利用ManualResetEvent类)
C# "Thread类Suspend()与Resume()已过时" 解决方法(利用ManualResetEvent类) 参考文章: (1)C# "Thread类Suspe ...
- getpriority java_Java Thread类的最终int getPriority()方法(带示例)
线程类final int getPriority()包java.lang.Thread.getPriority()中提供了此方法. 此方法用于返回此线程的优先级. 此方法不是静态的,因此该方法可通过T ...
- _thread_in_vm_Java Thread类的静态void sleep(long time_in_ms,int time_in_ns)方法,带示例
_thread_in_vm 线程类静态无效睡眠(long time_in_ms,int time_in_ns) (Thread Class static void sleep(long time_in ...
- java void方法_Java对象类的最终void wait(long ms)方法,包含示例
java void方法 对象类最终无效等待(长毫秒) (Object Class final void wait(long ms)) This method is available in java. ...
- Java Thread类的静态void sleep(long time_in_ms)方法,带示例
线程类静态无效睡眠(long time_in_ms) (Thread Class static void sleep(long time_in_ms)) This method is availabl ...
- Java LinkedList void clear()方法与示例
LinkedList void clear()方法 (LinkedList void clear() method) This method is available in package java. ...
- JavaSE基础二十:Java 多线程(线程基础知识、Java 多线程、Java 实现多线程(继承 Thread 类、实现 Runnable 接口、实现 Callable 接口))
本章目录 1.基础知识准备 2.Java 多线程概述 3.Java 实现多线程 3.1.继承 Thread 类 如何开启新线程 Thread 类常用方法 多线程中的同步 Thread 类同步方法 多线 ...
最新文章
- Rust 语言风靡学术界
- smarty半小时快速上手教程
- c语言奇数值结点链表,习题11-7 奇数值结点链表 (20 分)
- 【MFC】定义XP风格的工具栏
- 【算法训练】DAY1:整数反转
- 浅析如何掌握了解SQL Server的锁机制
- 第一部分 OpenStack及其构成简介
- 禁止tomcat的Catina.out的累计输出
- python给excel排序_python初学—-实现excel里面读数据进行排序
- 光洋PLC以太网通讯数据采集解决方案
- 蚁群算法原理介绍,算法框架以及代码实现
- java 200以内的素数_Java——200以内的质数
- 逍遥魔兽手动打开mysql_逍遥魔兽gm命令使用
- LeetCode 1114:按序打印
- 好玩有趣的 iOS URL Scheme
- 斐波那契常见规律(总结)
- Retrofit的封装
- 传感器如何将消息发送给云服务器,通过 NodeMCU (ESP8266) 将传感器数据上传至 MQTT 云服务...
- 更新:扫码即可实现丨用脚本快速查看自己被多少微信好友删除
- H5分享页面背景音乐及播放视频
热门文章
- TensorFlow构建二维数据拟合模型(3)
- python快递费用计算_[Python]简单用Python写个查询快递的程序最后附源代码
- super(Net,self).__init__() 的含义
- 6-搭建一个私有registry
- wordpress后台无法登录问题
- idou老师教你学Istio 27:解读Mixer Report流程
- 《Java EE 7精粹》—— 第3章 JSF 3.1 Facelets
- CentOS 创建SVN 服务器,并且自动同步到WEB 目录
- SublimeText2使用笔记
- 序列化包含多种不明类型的集合