Home Tutorial Java Core Java :Thread getPriority Example

 
 

Share on Google+Share on Google+
Java :Thread getPriority Example
Posted on: November 6, 2012 at 12:00 AM
Advertisement
In this tutorial you will learn how to get thread priority in java thread.

Java :Thread getPriority Example

In this tutorial you will learn how to get thread priority in java thread.

Thread getPriority() :

Thread scheduler uses thread priority concept to assign priority to the thread. A higher priority  threads execute first then the lower priority threads. You can set priority by using method setPriority () and get it by using method getPriority ().

public final int getPriority() : Return type is int. This method returns the priority of your thread.

Example :


class ThreadGetPriority implements Runnable{
		Thread thread;
		public ThreadGetPriority(){
			thread = new Thread(this);
			thread.start();
		}
	public void run() {
        /* getting Priority of the thread*/
        System.out.println( " Priority of "+thread.getName()+" is "+thread.getPriority());
        
        /* setting Priority of the thread*/
        thread.setPriority(6);
        
        /* getting Priority of the thread*/
        System.out.println(" New Priority of "+thread.getName()+" is "+thread.getPriority());
    }

    public static void main(String[] args) {
        new ThreadGetPriority();
        
    }
}

Output :

Priority of Thread-0 is 5
 New Priority of Thread-0 is 6
Advertisement

Related Tags for Java :Thread getPriority Example:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 6, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com