Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Networking TechnologyRSS Feeds

Program for Thread Priority

Posted By: Adelhelm Fischer     Category: Java     Views: 11861

Write a program for Thread Priority.

Code for Program for Thread Priority in Java

class thrun implements Runnable
{
      Thread t;
      boolean runn = true;

      thrun(String st,int p) 
      {
    t = new Thread(this,st);
    t.setPriority(p);
    t.start();
      }
    
      publicvoid run()
      {
    System.out.println("Thread name : " + t.getName());
    System.out.println("Thread Priority : " + t.getPriority());
      }     
    
}

class priority
{
      publicstaticvoid main(String args[])
      {
     Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
     thrun t1 = new thrun("Thread1",Thread.NORM_PRIORITY + 2);
     thrun t2 = new thrun("Thread2",Thread.NORM_PRIORITY - 2);
     System.out.println("Main Thread : " + Thread.currentThread());
     System.out.println("Main Thread Priority : " + Thread.currentThread().getPriority());
      }
}

/*
Output

Thread name : Thread1
Main Thread : Thread[main,10,main]
Thread name : Thread2
Thread Priority : 7
Main Thread Priority : 10
Thread Priority : 3

*/
  
Share: 


Didn't find what you were looking for? Find more on Program for Thread Priority Or get search suggestion and latest updates.

Adelhelm Fischer
Adelhelm Fischer author of Program for Thread Priority is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!