Share on Google+Share on Google+

Java Runnable Interface

Ads
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]

Advertisements

Posted on: November 7, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.

Ads

Advertisement