Java Thread.getId()

Syntax

Thread.getId() has the following syntax.

public long getId()

Example

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


class ThreadDemo implements Runnable {
   public void run() {
      // returns the identifier of this Thread.
      System.out.println("Name = " + Thread.currentThread().getName());
      System.out.print("Id = " + Thread.currentThread().getId());
   }//  www  . j a v  a 2  s . com
}

public class Main{


   public static void main(String args[]) {

      // thread created
     Thread t = new Thread("java2s.com thread");
      // set thread priority
      t.setPriority(1);
      // prints 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