Tuesday, January 20, 2015

Getting the priority in java pgm



Getting the priority

public class SimplePriorities extends Thread
{
   private int countDown = 5;
   private volatile double d = 0;
   public SimplePriorities(int priority)
  {
      setPriority(priority);
      start();
   }
   public String toString()
  {
      return super.toString() + ": " + countDown;
   }
   public void run()
  {
      while(true)
  {
         for(int i = 1; i < 100000; i++)
         d = d + (Math.PI + Math.E) / (double)i;
         System.out.println(this);
         if(--countDown == 0) return;
      }
   }
   public static void main(String[] args)
  {
      new SimplePriorities(Thread.Max_priority);
      for(int i = 0; i < 5; i++)
      new SimplePriorities(Thread.Min_priority);
   }
}

No comments:

Post a Comment