| Methods | Action Performed |
|---|---|
| currentThread() | Returns a reference to the currently executing thread object |
| dumpStack() | Prints a stack trace of the current thread to the standard error stream |
| enumerate(Thread[] tarray) | Copies into the specified array every active thread in the current thread's thread group and its subgroups |
Then, what are the different thread methods?
Introduction
| Method Signature | Description |
|---|---|
| void start() | This method will start a new thread of execution by calling run() method of Thread/runnable object. |
| void run() | This method is the entry point of the thread. Execution of thread starts from this method. |
Furthermore, what are the two methods thread can be created in Java? There are two ways to create a thread:
extends Thread class. implement Runnable interface.
Hereof, what are the three methods of thread class?
Commonly used methods of Thread class:
- public void run(): is used to perform action for a thread.
- public void start(): starts the execution of the thread.
- public void sleep(long miliseconds): Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
Which method is best for threading in Java?
Hence we are missing Inheritance benefits. In the second approach, while implementing Runnable interface we can extends any other class. Hence we are able to use the benefits of Inheritance. Because of the above reasons, implementing Runnable interface approach is recommended than extending Thread class.