Multi-threading is a process of executing multiple threads in parallel. In this tutorial, we will learn about Java Threads.
What is a Thread?
A thread (sometimes also called a lightweight process) is a basic processing unit to which an OS(Operating System) allocates the processor time. The JVM(Java Virtual Machine) allows the Java application to have multiple threads running concurrently.
Each thread has a priority. Threads set with higher priority are executed before threads with lower priority.
Create a Thread
There are two ways to create a thread in Java.
- Subclass Thread
- Implement Runnable Interface
One approach is to define a class to be a subclass of Thread. This subclass should override the run() method of the class Thread.
The second approach is to declare a class that implements the Runnable interface. The class can then implement the run() method. An instance of the class can then be allocated and passed as an argument when creating a Thread.
Java Tutorials on this website:
For more information on Java, visit the official website :