Java如何获得运行线程的优先级
2018-11-18 · 百度知道合伙人官方认证企业
关注
展开全部
package com.yiibai;public class GettingThreadPriority extends Thread {
private int countDown = 5;
private volatile double d = 0;
public GettingThreadPriority(int priority) {
setPriority(priority);
start();
}
public String toString() {
return super.toString() + ": " + countDown;
}
public void run() {
while (true) {
for (int i = 1; i < 100000; i++)
d = d + (Math.PI + Math.E) / (double) i;
System.out.println(this);
if (--countDown == 0)
return;
}
}
public static void main(String[] args) {
new GettingThreadPriority(Thread.MAX_PRIORITY);
for (int i = 0; i < 5; i++) {
new GettingThreadPriority(Thread.MIN_PRIORITY);
}
}}
private int countDown = 5;
private volatile double d = 0;
public GettingThreadPriority(int priority) {
setPriority(priority);
start();
}
public String toString() {
return super.toString() + ": " + countDown;
}
public void run() {
while (true) {
for (int i = 1; i < 100000; i++)
d = d + (Math.PI + Math.E) / (double) i;
System.out.println(this);
if (--countDown == 0)
return;
}
}
public static void main(String[] args) {
new GettingThreadPriority(Thread.MAX_PRIORITY);
for (int i = 0; i < 5; i++) {
new GettingThreadPriority(Thread.MIN_PRIORITY);
}
}}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询