Thread Methods in Java

14 Apr 2026, Updated: 05 Jul 2026 4 min read
0
In Java, threads are controlled and managed through a set of important methods provided by the Thread class. These methods define how threads are started, paused, coordinated, interrupted, and monitored.

In this article, we will explore the most commonly used thread methods: start(), run(), sleep(), yield(), join(), interrupt(), and isAlive().

start() vs run()

start()

The start() method is used to begin the execution of a thread. When you call start(), a new thread is created and the JVM internally calls the run() method.
        Thread t = new Thread(() -> {
            System.out.println("Thread executed using start()");
        });
        t.start();
Calling start() ensures that the task runs in a separate thread.

run()

The run() method contains the actual logic that the thread executes. However, calling run() directly does not create a new threadβ€”it simply runs like a normal method in the current thread.
        Thread t = new Thread(() -> {
            System.out.println("Inside run()");
        });
        t.run(); // NO new thread created 

sleep() and yield()

sleep()

The sleep() method pauses the execution of the current thread for a specified duration. During this time, the thread enters the TIMED_WAITING state.
        try {
            Thread.sleep(2000); // sleep for 2 seconds 
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

Important Points:

- Does not release locks
- Throws InterruptedException
- Used for delays, retries, or simulation

yield()

The yield() method is a hint to the thread scheduler that the current thread is willing to pause and allow other threads of the same priority to execute.
Thread.yield();

Important Points:

- It is only a hint, not guaranteed
- The thread may continue execution immediately
- Rarely used in real-world applications

join() and interrupt()

join()

The join() method is used when one thread needs to wait for another thread to complete before continuing execution.
        Thread t = new Thread(() -> {
            System.out.println("Child thread running");
        });
        t.start();
        t.join(); // main thread waits here
        System.out.println("Main thread resumes"); 

Output

Child thread running
Main thread resumes
Key Points:
- Causes the current thread to enter WAITING or TIMED_WAITING
- Ensures sequential execution when required

interrupt()

The interrupt() method is used to signal a thread that it should stop what it is doing. It does not forcibly terminate the thread but sets an interrupt flag.
        Thread t = new Thread(() -> {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                System.out.println("Thread interrupted!");
            }
        });
        t.start();
        t.interrupt(); 
Output
Thread interrupted!
When t.start() is called, a new thread begins execution and enters the sleep state for 5 seconds using Thread.sleep(5000).

Immediately after starting the thread, t.interrupt() is invoked from the main thread. This sends an interrupt signal to the sleeping thread.

Since the thread is currently in a blocking state (sleep), the interrupt causes Thread.sleep() to throw an InterruptedException.
Key Points:
- Used for cooperative thread termination
- Interrupts blocking methods like sleep(), wait(), join()
- Best practice for stopping threads safely

isAlive()

The isAlive() method checks whether a thread is still running or not. It returns true if the thread has been started and has not yet terminated.

        Thread t = new Thread(() -> {
            System.out.println("Running...");
        });
        System.out.println(t.isAlive()); // false
        t.start();
        System.out.println(t.isAlive()); // true

Use Cases:

- Monitoring thread status
- Debugging concurrent applications
- Ensuring thread completion

Putting It All Together

The following example demonstrates multiple thread methods working together:
public class ThreadDemo {
    static void main(String[] args) throws Exception {
        Thread t = new Thread(() -> {
            try {
                System.out.println("Thread started");
                Thread.sleep(1000);
                System.out.println("Thread finished");
            } catch (InterruptedException e) {
                System.out.println("Interrupted!");
            }
        });
        t.start();
        System.out.println("Is alive: " + t.isAlive());
        t.join();
        System.out.println("Main thread resumes after join");
    }
}
Output
Thread started
Is alive: true
Thread finished
Main thread resumes after join
In the next article, we will explore thread synchronization and how to manage shared resources effectively.
Nagesh Chauhan

Nagesh Chauhan

Principal Software Engineer β€’ Java β€’ Python β€’ Distributed Systems β€’ AI/ML

Principal Software Engineer with 14+ years of experience designing and delivering large-scale distributed systems, cloud-native applications, and AI-powered platforms.

Passionate about solving complex engineering problems using strong data structures and algorithms, along with expertise in Java, Spring Boot, Python, System Design, Microservices, Cloud, Kafka, Elasticsearch, and Generative AI.

Share this Article

πŸ’¬ Comments

Join the Discussion