Thread is a lightweight process. A process in execution is called a program. A subpart of a program is called a thread. Threads allow a program to operate more efficiently by doing multiple things at the same time performing complicated tasks in the background without interrupting the main program execution.
All threads can communicate with each other. Java provides a Thread class to achieve thread programming. Thread class provides constructors and methods to create and perform operations on a thread.
Various Thread Methods:
- start(): method is used to start the execution of the thread.
- run(): method is used to do an action.
- sleep(): This method sleeps a thread for the specified amount of time.
- resume(): This method is used to resume the suspended thread.
- stop(): This method is used to stop the thread.
- destroy(): This method is used to destroy the thread group and all of its subgroups.
public class Thread
Geeks for Geeks Geeks for Geeks Geeks for Geeks
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.