Java Thread setPriority() methodLast Updated : 17 Mar 2025 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. SyntaxParametera: It is the priority to set this thread to. ReturnIt does not return any value. ExceptionIllegalArgumentException: 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 ThreadOutput: Priority of thread is: 10 Example 2: Minimum Priority ThreadOutput: Priority of thread is: 1 Example 3: Normal Priority ThreadOutput: Priority of thread is: 5 Example 4: User define Priority ThreadOutput: Priority of thread t1 is: 4 Priority of thread t2 is: 7 running... Example 5: When priority is greater than 10Output: Exception in thread "main" java.lang.IllegalArgumentException at java.lang.Thread.setPriority(Thread.java:1089) at JavaSetPriorityExp5.main(JavaSetPriorityExp5.java:13) Next TopicMultithreading in Java |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India