gpt4 book ai didi

java - 优先级会影响同一台计算机上的其他程序吗?

转载 作者:行者123 更新时间:2023-11-29 05:45:41 24 4
gpt4 key购买 nike

我有这样的代码:

Thread thread = new Thread(new Runnable()
{
@Override
public void run()
{
//extremely time-consuming actions
}
});
thread.setPriority(Thread.MAX_PRIORITY);
thread.start();

该线程会做一些耗时的 Action ,它也有高优先级。

现在我想知道这个线程在我系统的所有其他程序中是否具有更高的优先级,或者它只是与同一程序的线程相比具有更高的优先级?

最佳答案

优先级在进程中的线程内,而不是跨进程。 JVM 甚至可能 choose to ignore the priority ,因此您甚至无法保证流程本身的优先级。

The JVM defines a range of ten logical priorities for Java threads, including:

java.lang.Thread.MIN_PRIORITY = 1

java.lang.Thread.NORM_PRIORITY = 5

java.lang.Thread.MAX_PRIORITY = 10

These values [1..10] are passed into Thread.setPriority(int) to assign priorities to Java threads. The default priority of a Java thread is NORM_PRIORITY. (A Java thread that doesn't explicitly call setPriority runs at NORM_PRIORITY.) A JVM is free to implement priorities in any way it chooses, including ignoring the value.

关于java - 优先级会影响同一台计算机上的其他程序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15917888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com