All About INTERFACE Runnable in Java

The runnable interface should be implemented by any class whose instances are intended to be executed by a thread. The class must define a method called run() in its body. run() method has no argument.
The structure of the Runnable interface is given below:

public interface java.lang.Runnable{
public abstract void run();
When an object implements Runnable interface, it creates a thread.To start the thread,Object's start() method is called from a separate thread.(Calling thread).
If mt is an instance of Thread, then mt.start() and are two different things.Calling will execute the run() method in the same thread which is calling this method. It won't create a new thread. On the other hand if mt.start() is called , it creates a new thread and execute the things in the new thread. So if any preconditions are there before the run() method will be ignored if only is called.
All About INTERFACE Runnable in Java All About INTERFACE Runnable in Java Reviewed by Animesh Chatterjee on September 18, 2018 Rating: 5

No comments:

Powered by Blogger.