1.

Write a program to show a single thread in Java.

Answer»

Java Program to show Single Thread

public class Main {
public static void main(String[] args) {
Thread t = Thread.currentThread();
t.setName("My Main Thread");
t.setPriority(7);
System.out.println(t);
System.out.println(t.getName());
System.out.println(t.getPriority());

}
}

Output

Thread[My Main Thread,7,main]
My Main Thread
7


Discussion

No Comment Found