By default, a thread inherits its priority from the program or thread that created it. It is possible
to set a thread's priority using the Thread. setPriority method. A runnable thread with the
highest priority is chosen first for execution. The setPriority method takes a value between
Thread.MIN_PRIORITY and Thread.MAX_PRIORITY as an argument.
For example, in RunThreads, if we were to add the following statements prior to starting
the threads:
threadl, setPriority(Thread.MIN_PRl0RITY) ;
thread2, setPriority(Thread.MAX_PRIORITY) ;
the result would be to output the thread2
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.