Thread Priority in Advanced Java Programming

Home  »  Java  »  Advance Java »  »  MultiThreading »  Thread Priority

For Executing a Program java Contains a Scheduler which Executes the Programs of java on the behalf of Priorities and because a Process or can Execute only one Thread at a time and the Priority of a Thread will determine which Thread will be Executed now and by default all the Threads have a Same Priorities. but if a Thread has a Higher Priority then this will be Executed First and then after other lower Priorities Thread will be Executed. Generally JAVA Provided us three types of Priorities those are MIN_ Priority , Max-Priority and Normal_ Priority They are used as.

1) MAX_PRIORITY
2) NORM_PRIORITY
3) MAX_PRIORITY

In this Minimum Priority of a thread has value 0 and Normal Priority has value 5 and Maximum Priority has a value 10.

The following example creates a new thread and starts it running:



The above code will be stored in the file called ThreadPriority.java, which on compilation will crate a class file called ThreadPriority.class. Now compile this file using below commands in the DOS mode:

C:\>jdk1.4\bin>javac ThreadPriority.java
C:\>jdk1.4\bin>java ThreadPriority



"Output of ThreadPriority.class"


Download Complete Program

  -  




MultiThreading


Thread Life Cycle Main Thread
Creating A Thread Thread Priority
Extending The Thread Class Writing Applets With Threads




No comments:

Post a Comment