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.
In the world of Java concurrency, understanding the difference between Thread's start() method and Runnable's run() method is pivotal for effective multi-threaded application development. Although it may seem subtle, the distinction has significant consequences for how threads are managed and executed.
Understanding the Basics
The Thread Class
Java provides the Thread class, which represents a thread of execution in a program. Thread is a part of the java.lang package and provides developers a way to create concurrent applications with ease.
The Runnable Interface
Runnable is a functional interface, also in the java.lang package. It is designed to provide a common protocol for objects that wish to execute code while they are active. The only method in this interface is run(), which must be defined by any class that implements the interface.
Key Differences Between Thread.start() and Runnable.run()
- Invocation:
Thread.start(): This method is used to initiate a thread. When invoked, it causes the JVM to call therun()method of the thread in a new call stack, effectively creating a new executing thread.Runnable.run(): This is merely a method call on the current thread; it does not involve any new thread creation. Invoking this method alone executes therun()method in the context of the current thread.
- Concurrency:
Thread.start(): Concurrency is achieved asstart()spawns a new thread that runs therun()method independently.Runnable.run(): No concurrency is achieved. The method simply runs on the already executing thread.
- Thread Lifecycle:
Thread.start(): Properly manages the thread lifecycle from new (not yet started) to runnable (executing) to terminated (finished execution).Runnable.run(): Does not manage any thread lifecycle as it does not start a separate thread.
- Error Handling:
Thread.start(): Since it creates a separate thread, any uncaught exceptions are handled by the thread'sUncaughtExceptionHandler.Runnable.run(): As it runs on the existing thread, any uncaught exception is propagated up the current call stack.
- Call Sequence:
Thread.start(): If called more than once on the sameThreadinstance, it will throw aIllegalThreadStateException.Runnable.run(): Can be called multiple times just like any other method.
Example Scenarios
Using Thread.start()
Using Runnable.run()
Comparison Overview
Below is a table summarizing the differences:
| Feature | Thread.start() | Runnable.run() |
| Invocation | Starts a new thread | Invokes a method on the current thread |
| Concurrency | Achieves concurrency | No concurrency |
| Thread Lifecycle | Manages lifecycle from new -> runnable -> terminated | No lifecycle management |
| Error Handling | Handled by UncaughtExceptionHandler | Propagated up the current call stack |
| Call Sequence | Throws IllegalThreadStateException if called multiple times on same instance | Can be called multiple times without issue |
Additional Considerations
Performance Implications
Using Thread.start() involves more overhead due to the creation and management of a new thread. While modern JVMs efficiently handle threads, excessive thread creation can impact performance. On the other hand, invoking run() has no threading overhead but will not leverage the benefits of multi-core processors.
Best Practices
- Prefer Implementing
Runnable: It is generally recommended to implementRunnablerather than extendingThread. This promotes better object-oriented design, as Java supports single inheritance and usingRunnableallows for more flexible class hierarchies. - Use Executors for Complex Applications: For applications requiring extensive multithreading, consider utilizing the
java.util.concurrent.Executorframework. It manages thread creation and provides a more comprehensive set of features.
Understanding these differences will aid in making informed decisions when designing concurrent Java applications, ensuring both efficiency and reliability in execution.
Related reading
- What's the difference between Thread start and Runnable run
- 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 difference between ZonedDateTime and OffsetDateTime?
- What's the Kotlin equivalent of Java's String?
- What's the meaning of UseTaskFriendlySynchronizationContext?
- What's the point of multithreading in Python if the GIL exists?

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.