Java Runnable Interface


 

Java Runnable Interface

In this segment of tutorial we will learn about the Runnable Interface and its use.Then We will create an example for the Runnable Interface and print the content.

In this segment of tutorial we will learn about the Runnable Interface and its use.Then We will create an example for the Runnable Interface and print the content.

  • Java Runnable Thread is a piece of the program execution.
  • Java Runnable is an interface. Thread class implements it.
  • Java has multithreading facility.
  • Thread is also created by implementing the Runnable interface.


Java Runnable Thread Example
public class runnable1 implements Runnable {
	@Override
	public void run() {
		for (int x = 1; x <= 3; x++) {
			System.out.println(x + " Thread name, priority and group are    "
					+ Thread.currentThread());		}
	}

	public static void main(String[] args) {
		runnable1 run1 = new runnable1();
		Thread t1 = new Thread(run1);
		t1.start();
	}
}
Output 1 Thread name, priority and group are Thread[Thread-0,5,main] 2 Thread name, priority and group are Thread[Thread-0,5,main] 3 Thread name, priority and group are Thread[Thread-0,5,main]

Ads