Share on Google+Share on Google+

Java Thread class

Advertisement
In this segment of tutorial we will learn about the Java Thread Class and how it is used. Then We will create the thread class and print the output.

  • Java Thread Class is a piece of the program execution
  • Java has multithreading facility.
  • It allows multiple works(threads) to run at a time
  • It is created by extending the Thread class or implementing Runnable interface


Java Thread Class Example
public class thread1 extends Thread {
	@Override
	public void run() {
		for (int i = 1; i < 4; i++) {
			System.out.println("This is thread  " + i);
		}
	}

	public static void main(String[] args) {
		thread1 t1 = new thread1();
		t1.start();
	}
}

Output

This is thread  1
This is thread  2
This is thread  3


Advertisements

Posted on: November 6, 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.