Thread in JAVA

taxiongo

Member
A thread in Java is the path followed when executing a program. Thread is created by the Java Virtual Machine (JVM). All Java programs have at least one thread, known as the main thread. Multiple threads can be performed at the same time with different task. It is used to make Java application faster, also thread helps to achieve parallelism in Java programs.
 
Thread in Java is the direction or path that is taken while a program is being executed. Generally, all the programs have at least one thread, known as the main thread, that is provided by the JVM or Java Virtual Machine at the starting of the program's execution.

There are two ways to create a thread.

It can be created by extending the Thread class and overriding its run() method:

public class Main extends Thread {
public void run() {
System.out.println("This code is running in a thread");
}
 
Back
Top