The main thread is the initial thread that typically executes the main() method when a Java application starts. It can create and start additional threads during program execution.
- Its default name is main and its normal priority is 5.
- The JVM typically continues running until all started non-daemon threads terminate, unless explicit shutdown occurs.

The JVM manages application threads along with background threads that perform tasks such as garbage collection.
Accessing the Main Thread
The Thread.currentThread() method returns a reference to the currently executing thread.
Syntax:
Thread t = Thread.currentThread();
Example: Accessing and modifying the main thread.
class Geeks{
public static void main(String[] args){
Thread t = Thread.currentThread();
System.out.println("Name: " + t.getName());
System.out.println("Priority: " + t.getPriority());
t.setName("Geeks");
t.setPriority(Thread.MAX_PRIORITY);
System.out.println("New name: " + t.getName());
System.out.println("New priority: " + t.getPriority());
}
}
Output
Name: main Priority: 5 New name: Geeks New priority: 10
Explanation: The program retrieves the main thread and modifies its name and priority using setName() and setPriority().
Creating a Thread from the Main Thread
The main thread can create additional threads to execute tasks concurrently. A newly created platform thread normally inherits the priority of its creating thread.
class Geeks{
public static void main(String[] args){
Thread.currentThread().setPriority(8);
Thread t = new Thread(() ->{
System.out.println("Child thread executing");
});
System.out.println("Child priority: " + t.getPriority());
t.start();
}
}
Output
Child priority: 8 Child thread executing
Explanation: The new platform thread inherits the main thread's priority. The start() method begins its execution independently.
Thread priority does not guarantee execution order. Refer to Multithreading in Java to learn more.
Main Thread Vs main() Method
Main Thread | main() Method |
|---|---|
Represents a thread of execution. | Serves as the application entry point. |
Executes application code. | Defines the initial code to execute. |
Can create additional threads. | Can contain statements to create threads. |
Has properties such as name and priority. | Follows Java's application launch requirements. |
Note: Java 25 also supports certain instance main() methods and parameterless main() methods.
Deadlock in the Main Thread
A main thread can become indefinitely blocked if it calls join() on itself.
class Geeks{
public static void main(String[] args)
throws InterruptedException{
System.out.println("Entering deadlock");
Thread.currentThread().join();
System.out.println("Execution completed");
}
}
Output:
Entering DeadlockExplanation: The main thread waits for its own termination, preventing further execution unless the wait is interrupted.
Important Thread Methods
Method | Description |
|---|---|
| Returns the currently executing thread. |
| Returns the thread name. |
| Changes the thread name. |
| Returns the thread priority. |
| Changes the priority of a platform thread. |
Starts a thread. | |
Waits for a thread to terminate. | |
| Checks whether a thread has started and not yet terminated. |
Related Article: