Home Tutorial Java Thread Java Runnable Interface

 
 

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

Related Tags for Java Runnable Interface:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 7, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com