Thread Class: Thread class is the main class on which Java's Multithreading system is based. Thread class, along with its companion interface Runnable will be used to create and run threads for utilizing Multithreading feature of Java.
Constructors of Thread class:
- Thread ( )
- Thread (String str)
- Thread (Runnable r)
- Thread (Runnable r, String str)
You can create new thread, either by extending Thread class or by implementing Runnable interface. Thread class also defines many methods for managing threads. Some of them are:
Method | Description |
setName() | to give thread a name |
getName() | return thread's name |
getPriority() | return thread's priority |
isAlive() | checks if thread is still running or not |
join() | Wait for a thread to end |
run() | Entry point for a thread |
sleep() | suspend thread for a specified time |
start() | start a thread by calling run() method |