Multithreading in Java

Developer Helps
developerhelps
Published in
2 min readAug 23, 2020

Multithreading in java is a process that allows executions of multiple threads in java. It helps in the maximum utilization of the CPU. We call each part of the program as a thread so multithreading helps in the executions of multiple parts of a program at a single time. Multithreading helps to create small multiple tasks in the application where we can subdivide the operations into single threads and perform the tasks.
The cycle of the thread works in the following manner:

New thread() ->New -> Runnable -> Running -> Waiting -> Dead

New thread() ->New -> Dead

Description is as follows:

New: When a new state of the cycle is formed, the new life of the thread begins.

Runnable: we put a thread in the category of runnable when a new thread starts to perform action.

Waiting: when a thread is already performing a task, the other thread is kept on hold or wait. Once the previous thread finishes its task, the new thread comes into play.

Dead: we call a thread dead or in terminated state when it completes its task.

package Test;
public class DeveloperHelps implements Runnable
{
public static void main(String[] args) {
Thread T1 = new Thread("Thread 1 works");
Thread T2 = new Thread("Thread 2 works");
T1.start();
T2.start();
System.out.println("Thread names are following:");
System.out.println(T1.getName());
System.out.println(T2.getName());
}
@Override
public void run() {
}
}

The output of the above program will be:

The names of the threads are:
Thread 1 works
Thread 2 works

Read More : Multithreading in Java

More Examples
Collections in Java
Logical operators in Java with Example [2020]

--

--

Developer Helps
developerhelps

Developer Helps will provides to you latest Tutorials regarding PHP, MySQL and much more.