Java Thread.setName(String name)
Syntax
Thread.setName(String name) has the following syntax.
public final void setName(String name)
Example
In the following code shows how to use Thread.setName(String name) method.
public class Main {
//from ww w .j a v a 2 s . c o m
public static void main(String[] args) {
Thread t = Thread.currentThread();
System.out.println("Thread = " + t);
t.setName("java2s.com thread");
System.out.println("Thread after changing name = " + t);
int count = Thread.activeCount();
System.out.println("currently active threads = " + count);
}
}