What's the difference between Thread start and Runnable run
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In Java, multithreading is essential for improving the efficiency of applications by allowing tasks to be executed concurrently. Two fundamental concepts in multithreading are the Thread class and the Runnable interface. While both are used to create and manage threads, they have distinct methods that are essential to understand: Thread.start() and Runnable.run(). This article delves into the differences between these methods, explaining their purposes and usage through technical explanations and examples.
Thread and Runnable in Java
Before diving into the differences, it's crucial to understand what Thread and Runnable represent:
- Thread: A
Threadis an independent path of execution through a program. TheThreadclass provides methods to start and manage the threads. - Runnable:
Runnableis a functional interface with a single method,run(). It's designed to provide a standard way of defining tasks to be executed by threads.
Key Differences
Purpose
- Thread.start():
- The
start()method is responsible for creating a new thread and making it eligible for execution. - It initiates the thread's
run()method. - It is only available in the
Threadclass.
- Runnable.run():
- The
run()method is designed to encapsulate the task to be executed within a thread. - It doesn't create a new thread on its own.
- It is suitable primarily for defining the logic that will be executed asynchronously.
Behavior
- Thread.start():
- When invoked, a new call stack is allocated for the thread, and the
run()method is called in that new thread. - Starting a thread more than once throws
IllegalThreadStateException.
- Runnable.run():
- The
run()method is called like a normal method, and it executes in the current thread stack. - It does not initiate a new thread.
Example
Output (Example):
- In the example, calling
start()formyThreadcreates a new thread, whiletask.run()executes in the main thread.
Summary Table
| Feature | Thread.start() | Runnable.run() |
| Function | Starts a new thread | Executes task within the current thread without starting a new one |
| Thread Allocation | Allocates a new call stack for the thread | Does not allocate a new call stack (runs in current stack) |
| Repeated Calls | Throws IllegalThreadStateException
if called more than once | Can be called multiple times without issues |
| Use Case | Creates a new path of execution | Encapsulates thread execution logic without creating a new thread |
Additional Details
Use Cases and Considerations
- When to use
Thread.start():- Use when you need to independently execute tasks that require separate call stacks.
- Suitable for computationally intensive tasks that can be distributed across multiple cores.
- When to use
Runnable.run():- Use for defining the logic of tasks without managing threads yourself.
- Often used in frameworks or APIs where the API itself will handle the thread management.
Best Practices
- Prefer using
RunnablewithThreador executors from thejava.util.concurrentpackage, as they allow for better separation of task definition and execution. - Utilize higher-level concurrency constructs such as
ExecutorService,ForkJoinPoolfor cleaner and more robust multithreading solutions.
In conclusion, understanding the difference between Thread.start() and Runnable.run() is critical for effective multithreading in Java. By adhering to best practices and leveraging the strengths of each approach, developers can create efficient, scalable, and maintainable multithreaded applications.
Related reading
- What's the equivalent of Java's Thread.sleep in JavaScript?
- What's the equivalent of Java's Thread.sleep in Objective-C/Cocoa?
- What's the meaning of an object's monitor in Java? Why use this word?
- What's the meaning of UseTaskFriendlySynchronizationContext?
- What's the difference between ZonedDateTime and OffsetDateTime?
- What's the Kotlin equivalent of Java's String?
- What's the point of multithreading in Python if the GIL exists?
- What's the point of using Future without multithreading?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.