How do I get the currently executing thread?
To get the currently executing thread, use the static currentThread() method of the Thread class. This method returns a reference of the currently executing thread object. package org.kodejava.lang; public class GetCurrentThreadDemo { public static void main(String[] args) { // Get the currently executing thread object Thread thread = Thread.currentThread(); System.out.println("Id : " + thread.getId()); System.out.println("Name […]
Article by Wayan · Source: Kode Java ↗
To get the currently executing thread, use the static currentThread() method of the Thread class. This method returns a reference of the currently executing thread object.
package org.kodejava.lang;
public class GetCurrentThreadDemo {
public static void main(String[] args) {
// Get the currently executing thread object
Thread thread = Thread.currentThread();
System.out.println("Id : " + thread.getId());
System.out.println("Name : " + thread.getName());
System.out.println("Priority: " + thread.getPriority());
}
}
The code snippet print the following output:
Id : 1
Name : main
Priority: 5
Comments 0
Share your questions, experiences, or feedback about this article.
Sign in with Google to leave a comment.
Sign in with Google
No comments yet. Be the first to share your feedback.