LogRecord getThreadID() method in Java with Examples
The getThreadID() method of java.lang.reflect.LogRecord is used to get an identifier for the thread where the message originated. This method is helpful to identify thread which generates the logger message.
Syntax:
public int getThreadID()
Parameters: This method accepts nothing.
Return: This method returns thread ID.
Below programs illustrate getThreadID() method:
Program 1:
// Java program to illustrate // getThreadID() method import java.util.logging.Level; import java.util.logging.LogRecord; public class GFG { public static void main(String[] args) { // Create LogRecord object LogRecord logRecord = new LogRecord(Level.SEVERE, "Hello Logger" ); // get Thread ID int id = logRecord.getThreadID(); // print System.out.println( "Thread ID = " + id); } } |
Thread ID = 1
Program 2:
// Java program to illustrate // getThreadID() method import java.util.logging.Level; import java.util.logging.LogRecord; public class GFG { public static void main(String[] args) { // start the Thread Thread thread1 = new Thread1(); thread1.start(); // Create LogRecord object LogRecord logRecord = new LogRecord(Level.SEVERE, "Hello Logger" ); logRecord.setThreadID(( int )thread1 .getId()); // get Thread ID int id = logRecord.getThreadID(); // print System.out.println( "Thread ID = " + id); } } class Thread1 extends Thread { public void run() { System.out.println( "Thread is running..." ); } } |
Thread is running... Thread ID = 11
References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#getThreadID()
Recommended Posts:
- LogRecord getSourceClassName() method in Java with Examples
- LogRecord getParameters() method in Java with Examples
- LogRecord getSequenceNumber() method in Java with Examples
- LogRecord getInstant() method in Java with Examples
- LogRecord setSequenceNumber() method in Java with Examples
- LogRecord setResourceBundle() method in Java with Examples
- LogRecord getSourceMethodName() method in Java with Examples
- LogRecord setResourceBundleName() method in Java with Examples
- LogRecord setInstant() method in Java with Examples
- LogRecord setMillis() method in Java with Examples
- LogRecord setThreadID() method in Java with Examples
- LogRecord getMillis() method in Java with Examples
- LogRecord getResourceBundleName() method in Java with Examples
- LogRecord getResourceBundle() method in Java with Examples
- LogRecord getThrown() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.