How to setPriority of Thread Class?

In this blog, we will see Thread Class and its object, we also see setPriority and setName method for setting of thread properties.

Let’s see example and video on Thread Class.

package examples;

public class Thread2

{

                public static void main(String[] args)

                {

                                Thread t = Thread.currentThread();         // Process of creating an object

                                System.out.println(t);

 

                                // Change Name of thread and priority of thread

                                t.setName(“Process -1”);

                                t.setPriority(10);               // 1  to 10

                                System.out.println(t);

 

                                Thread t1 = new Thread();

                                System.out.println(t1);

                }

}

Output:

Thread [main, 5, main]

Thread [Process-1, 10, main]

Thread [Thread-0, 10, main]

 

Video available on YouTube.

 


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe our website


Earn Money Online

563total visits,8visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image