在thread类中,定义了三个静态值来表示线程的优先级:
max_priority这是最高的线程优先级,值为10。
norm_priority这是默认的线程优先级,值为5。
min_priority这是最低的线程优先级,值为1。
语法public final int getpriority()
examplepublic class threadprioritytest extends thread { public static void main(string[]args) { threadprioritytest thread1 = new threadprioritytest(); threadprioritytest thread2 = new threadprioritytest(); threadprioritytest thread3 = new threadprioritytest(); system.out.println("default thread priority of thread1: " + thread1.getpriority()); system.out.println("default thread priority of thread2: " + thread2.getpriority()); system.out.println("default thread priority of thread3: " + thread3.getpriority()); thread1.setpriority(8); thread2.setpriority(3); thread3.setpriority(6); system.out.println("new thread priority of thread1: " + thread1.getpriority()); system.out.println("new thread priority of thread2: " + thread2.getpriority()); system.out.println("new thread priority of thread3: " + thread3.getpriority()); }}
输出default thread priority of thread1: 5default thread priority of thread2: 5default thread priority of thread3: 5new thread priority of thread1: 8new thread priority of thread2: 3new thread priority of thread3: 6
以上就是在java中,线程优先级的重要性是什么?的详细内容。
