Posts

Showing posts with the label Thread priority in java with example

Thread priority in java with example

Thread priority is useful to maintain threads in an order in java. When multiple threads are created and started, a 'Thread Scheduler' program will load all threads into JVM memory and executes them based on thread priority. This scheduler will allot more JVM time to those threads which are having higher priorities.           The priority number of a thread will change from 1 to 10. The minimum priority ( Thread.MIN_PRIORITY ) of a thread is 1, and the maximum priority ( Thread.MAX_PRIORITY ) is 10. The normal priority of a thread ( Thread.NORM_PRIORITY ) is 5. Example: Let us write a program to understand the thread priority. The thread with higher priority number will complete its execution first. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 package com . javatbrains . threads ; class ThreadPriority extends Thread { int count = 0 ; publi...