ThreadGroup类getMaxPriority()方法
- getMaxPriority() 方法在 java.lang 包中可用。
- getMaxPriority() 方法用于返回该线程组中存在的线程的最高优先级,并且该线程组中没有线程的优先级必须高于最大优先级。
- getMaxPriority() 方法是一个非静态方法,它只能通过类对象访问,如果我们尝试使用类名访问方法,那么我们将得到一个错误。
- getMaxPriority() 方法在返回该线程组的最大优先级时不抛出异常。
用法:
public final int getMaxPriority();
参数:
- 它不接受任何参数。
返回值:
这个方法的返回类型是int
– 返回该线程组中存在的线程的最大优先级。
例:
// Java program to demonstrate the example
// of int getMaxPriority() method of ThreadGroup
public class GetMaxPriority implements Runnable {
public static void main(String[] args) {
GetMaxPriority max_pri = new GetMaxPriority();
max_pri.maxPriority();
}
public void maxPriority() {
try {
// Create two thread group and the named are base
// and derived
ThreadGroup base = new ThreadGroup("Base ThreadGroup");
ThreadGroup derived = new ThreadGroup(base, "Derived ThreadGroup");
// create two threads
Thread th1 = new Thread(base, this);
Thread th2 = new Thread(derived, this);
// By using getName() method is to retrieve the
// name of the thread th1
System.out.println(th1.getName() + " " + "begins.....");
// By using start() method is to start its execution
// of thread th1
th1.start();
// By using getName() method is to retrieve the
// name of the thread th2
System.out.println(th2.getName() + " " + "begins.....");
// By using start() method is to start its execution
// of thread th2
th2.start();
System.out.println();
// By using getMaxPriority() method is to return the
// maximum priority of the base and derived thread group
System.out.println("base.getMaxPriority():" + " " + base.getMaxPriority());
System.out.println("derived.getMaxPriority():" + " " + derived.getMaxPriority());
// By using join() method is to wait the current
// thread till complete execution of another
// thread
th1.join();
th2.join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
// Override run()
public void run() {
for (int k = 0; k < 100; ++k)
++k;
System.out.println(Thread.currentThread().getName() + " " + "ends.....");
}
}
输出
Thread-0 begins..... Thread-1 begins..... Thread-0 ends..... Thread-1 ends..... base.getMaxPriority():10 derived.getMaxPriority():10
相关用法
- Java ThreadGroup getParent()用法及代码示例
- Java ThreadGroup getName()用法及代码示例
- Java ThreadGroup enumerate()用法及代码示例
- Java ThreadGroup parentOf()用法及代码示例
- Java ThreadGroup interrupt()用法及代码示例
- Java ThreadGroup suspend()用法及代码示例
- Java ThreadGroup setDaemon()用法及代码示例
- Java ThreadGroup isDaemon()用法及代码示例
- Java ThreadGroup checkAccess()用法及代码示例
- Java ThreadGroup resume()用法及代码示例
- Java ThreadGroup isDestroyed()用法及代码示例
- Java ThreadGroup toString()用法及代码示例
- Java ThreadGroup destroy()用法及代码示例
- Java ThreadGroup list()用法及代码示例
- Java ThreadGroup stop()用法及代码示例
- Java ThreadGroup activeCount()用法及代码示例
- Java ThreadGroup setMaxPriority()用法及代码示例
- Java ThreadGroup activeGroupCount()用法及代码示例
- Java Thread toString()用法及代码示例
- Java Thread interrupted()用法及代码示例
注:本文由纯净天空筛选整理自Preeti Jain大神的英文原创作品 Java ThreadGroup getMaxPriority() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。