Java Thread.getName()

Syntax

Thread.getName() has the following syntax.

public final String getName()

Example

In the following code shows how to use Thread.getName() method.


/* ww w  .ja va2  s  . c o  m*/
class ThreadDemo extends Thread {
  public void run() {
    // returns the name of this Thread.
    System.out.println("Name = " + getName());
  }
}

public class Main {
  public static void main(String args[]) {
    Thread t = new Thread(new ThreadDemo(), "java2s.com thread");
    // set thread priority
    t.setPriority(1);
    // print thread created
    System.out.println("thread  = " + t);
    // this will call run() function
    t.start();
  }

}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable