![]() |
VOOZH | about |
When a Java program starts, the Java Virtual Machine (JVM) creates a thread automatically called the main thread. This thread executes the main() method and controls the overall execution flow of the program.
The main thread is created automatically when the program starts. To control it, we must first obtain a reference to it using Thread.currentThread(). This method returns a reference to the currently executing thread.
Current thread: main After name change: Geeks Main thread priority: 5 Main thread new priority: 10 Main thread Main thread Main thread Main thread Main thread Child thread priority: 10 Child thread new priority: 1 Child thread Child thread Child thread Child thread Child thread
Explanation:
Even a single main thread can cause deadlock if it waits for itself.
Output:
๐ ImageExplanation: