toString(): This method is available in the java.lang.Thread class of Java.
Syntax:
String java.lang.Thread.toString()
This method returns a string representation of this thread, including the thread's name, priority, and thread group.
Parameters: NA
Returns: a string representation of this thread.
Exceptions: NA
Approach
Java
package com.Thread;public class ThreadtoString {public static void main(String[] args) {Thread thread = new Thread();System.out.println(thread.toString());}}
Output:
Thread[Thread-0,5,main]
Some other methods of Thread
getUncaughtExceptionHandler(): This method returns the handler invoked when this thread abruptly terminates due to an uncaught exception.
Thread.holdsLock(Object): This method returns true if and only if the current thread holds the monitor lock on the specified object.
interrupt(): This method interrupts this thread.
Thread.interrupted(): This method tests whether the current thread has been interrupted. The interrupted status of the thread is cleared by this method.
isAlive(): This method tests if this thread is alive. A thread is alive if it has been started and has not yet died.
isDaemon(): This method tests if this thread is a daemon thread.
isInterrupted(): This method tests whether this thread has been interrupted. The interrupted status of the thread is unaffected by this method.
join(): This method waits for this thread to die.
join(long): This method waits at most millis milliseconds for this thread to die. A timeout of 0 means waiting forever.
join(long, int): This method waits at most millis milliseconds plus nanos nanoseconds for this thread to die. If both arguments are 0, it means to wait forever.
Thread.onSpinWait(): This method indicates that the caller is momentarily unable to progress, until the occurrence of one or more actions on the part of other activities.
run(): If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
setContextClassLoader(ClassLoader): This method sets the context ClassLoader for this Thread.
setDaemon(boolean): This method marks this thread as either a daemon thread or a user thread.
setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler): This method set the default handler invoked when a thread abruptly terminates due to an uncaught exception, and no other handler has been defined for that thread.
setName(String): This method changes the name of this thread to be equal to the argument name.
setPriority(int): This method changes the priority of this thread.
setUncaughtExceptionHandler(UncaughtExceptionHandler): This method set the handler invoked when this thread abruptly terminates due to an uncaught exception.
Thread.sleep(long): This method causes the currently executing thread to sleep for a specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers.
Thread.sleep(long, int): This method causes the currently executing thread to sleep for the specified number of milliseconds plus the specified number of nanoseconds, subject to the precision and accuracy of system timers and schedulers.
start(): This method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
toString(): This method returns a string representation of this thread, including the thread's name, priority, and thread group.
Thread.yield(): This method is a hint to the scheduler that the current thread is willing to yield its current use of a processor.
No comments:
Post a Comment