adsense


Showing posts with label JAVA EXAMPLES SETTING THE PRIORITY. Show all posts
Showing posts with label JAVA EXAMPLES SETTING THE PRIORITY. Show all posts

Saturday, 31 October 2015

JAVA EXAMPLES SETTING THE PRIORITY PAGE 190

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES SETTING THE PRIORITY








Java Examples - Setting the priority


Problem Description:
How to set the priority of a thread?
Solution:
Following example how to set the priority of a thread with the help of.
public class Main {
   public static void main(String[] args) 
   throws Exception {
      Thread thread1 = new Thread(new TestThread(1));
      Thread thread2 = new Thread(new TestThread(2));
      thread1.setPriority(Thread.MAX_PRIORITY);
      thread2.setPriority(Thread.MIN_PRIORITY);
      thread1.start();
      thread2.start();
      thread1.join();
      thread2.join();
      System.out.println("The priority has been set.");
   }
}
Result:
The above code sample will produce the following result.
The priority has been set.