Saturday, 10 June 2017

Java Tutorial: Java Threads (Thread priority in java | Java Thread priority) ~ foundjava


Click here to watch in Youtube :

Click the below Image to Enlarge
Java Tutorial: Java Threads (Thread priority in java | Java Thread priority) 
DisplayThread.java
class DisplayThread extends Thread
{
    public static void main(String args[])
    {
        DisplayThread displayThread1 = new DisplayThread();
        DisplayThread displayThread2 = new DisplayThread();
        DisplayThread displayThread3 = new DisplayThread();

        displayThread1.setPriority(Thread.MIN_PRIORITY);
        displayThread2.setPriority(Thread.NORM_PRIORITY);
        displayThread3.setPriority(Thread.MAX_PRIORITY);

        displayThread1.start();
        displayThread2.start();
        displayThread3.start();

    }

    public void run()
    {
        System.out.println("Thread name = " + Thread.currentThread().getName()
                + ", Thread Priority = " + Thread.currentThread().getPriority()
                + "\n");

    }
}
Output
Thread name = Thread-1, Thread Priority = 5

Thread name = Thread-0, Thread Priority = 1

Thread name = Thread-2, Thread Priority = 10


Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment