Business Studies, asked by ravendrakumar2567, 1 year ago

What is Thread ? How to set the priority of Thread.

Answers

Answered by deeksha7790
18

Thread - JVM selects to run a Runnable thread with the highest priority. All Java threads have a priority in the range 1-10. Whenever a new Java thread is created it has the same priority as the thread which created it.

To set priority of Thread - :

Each Java thread is given a numeric priority between MIN_PRIORITY and MAX_PRIORITY (constants defined in the Thread class). At any given time, when multiple threads are ready to be executed, the thread with the highest priority is chosen for execution.

Hope it helps!


shan25743pbezma: Threads always run with some priority, usually represented as a number between 1 and 10 (although in some cases the range is less than 10). A thread gets a default priority that is the priority of the thread of execution that creates it.

But, you can also set a thread’s priority directly by calling the setPriority() method on a Thread instance. One thing to remember about thread priorities is never rely on thread priorities, because thread-scheduling priority behavior is not guaranteed.
Similar questions