Java basics
getID()
The java.lang.Thread.getId() method returns the identifier of this Thread. The thread ID is a positive long number generated when this thread was created.
The thread ID is unique and remains unchanged during its lifetime. When a thread is terminated, this thread ID may be reused.
Syntax:public long getId()
Example:import java.lang.*;
public class ThreadDemo implements Runnable {
Thread t;
ThreadDemo() {
// thread created
t = new Thread(this, "Admin Thread");
// set thread priority
t.setPriority(1);
// prints thread created
System.out.println("thread = " + t);
// this will call run() function
t.start();
}
public void run() {
// returns the identifier of this Thread.
System.out.println("Name = " + t.getName());
System.out.print("Id = " + t.getId());
}
public static void main(String args[]) {
new ThreadDemo();
}
}
Content
License.
All information of this service is derived from the free sources and is provided solely in the form of quotations.
This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 986 / 159176094. Delta: 0.00328 с