What is Runnable interface in Java?
Rohit Gupta
Select an image from your device to upload
The runnable interface must be implemented by any class, whose instances are intended to be executed by a thread. The Runnable interface has only one run() method.
public void run()
This method is used to perform an action for a thread.
For a detailed tutorial on Java MultiThreading, visithttps://www.c-sharpcorner.com/article/a-complete-multithreading-tutorial-in-java/
Java runnable is an interface used to execute code on a concurrent thread. It is an interface which is implemented by any class if we want that the instances of that class should be executed by a thread.
public class ExampleClass implements Runnable {
@Override public void run() { System.out.println("Thread has ended"); } public static void main(String[] args) { ExampleClass ex = new ExampleClass(); Thread t1= new Thread(ex); t1.start(); System.out.println("Hi"); }
@Override
public void run() {
System.out.println("Thread has ended");
}
public static void main(String[] args) {
ExampleClass ex = new ExampleClass();
Thread t1= new Thread(ex);
t1.start();
System.out.println("Hi");