Java Thread setPriority() method
The setPriority() method of thread class is used to change the thread's priority. Every thread has a priority which is represented by the integer number between 1 to 10.
Thread class provides 3 constant properties:
We can also set the priority of thread between 1 to 10. This priority is known as custom priority or user defined priority.
a: It is the priority to set this thread to.
It does not return any value.
IllegalArgumentException: This exception throws if the priority is not in the range MIN_PRIORITY to MAX_PRIORITY.
SecurityException: This exception throws if the current thread cannot modify this thread.
Example 1: Maximum Priority ThreadTest it Now
Priority of thread is: 10
Example 2: Minimum Priority ThreadTest it Now
Priority of thread is: 1
Example 3: Normal Priority ThreadTest it Now
Priority of thread is: 5
Example 4: User define Priority ThreadTest it Now
Priority of thread t1 is: 4 Priority of thread t2 is: 7 running...
Example 5: When priority is greater than 10Test it Now
Exception in thread "main" java.lang.IllegalArgumentException at java.lang.Thread.setPriority(Thread.java:1089) at JavaSetPriorityExp5.main(JavaSetPriorityExp5.java:13)