Home Tutorial Java Thread Java Runnable Interface

 
 

Java Runnable Interface
Posted on: November 7, 2009 at 12:00 AM
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]

Related Tags for Java Runnable Interface:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.