Home Java Thread What Is Thread In Java?


Share on Google+Share on Google+

What Is Thread In Java?

This section "what is thread in java?" will describe you about threading in Java.

What Is Thread In Java?

In this section we will read about thread in Java. Here you will see the definition of thread, a very simple example of thread execution and the description of the example.

Before, defining a Thread in Java we will first focus on some points which are required to know in advance before knowing about Thread. So, lets first discuss about what is program?, what is process ?

What Is Program?

Program is a set of instructions that are executed sequentially.

What Is Process?

A process is a program that specifies how a specific task should be done. Basically, it follows a sequence for executing. It is a collection of instructions that are executed at the same time at run time . That's why more than one processes can be associated with the same program.


Definition : Thread is a process which does the special task after executing. This is a lightweight process that resides inside the program. Like, a Process more than one thread can also be associated with a single process. So, a process with single thread called single threaded process whereas, process with multiple thread is called Multi-threaded process.

Thread In Java

Thread in Java has implemented with the same meaning that actually, it is defined. Every Java program is run as a thread, thread is a sequential path of code execution within a program. Thread in Java follows a life cycle from its creation to dead. Threads can define their own variables, they have the program counter that specifies the execution of threads.


Here I am giving a simple example which will demonstrate you about how to write thread in Java. Here we are going to give Java single thread example where you will see how a single thread is processed. In Java Thread can be used by two ways either by extending a Thread class or by implementing a Runnable interface. Here we will give the two examples, one will explain you that how to create a thread by extending and the another will explain you how to create thread by implementing the interface.

Thread Example using extending Thread class


 class MyThread extends Thread{

  String s=null;

  MyThread(String s1){
  public void run(){


public class RunThread{
  public static void main(String args[]){
  MyThread m1=new MyThread("Thread Example Using Extending Thread Class");  

Thread Example using implementing Runnable interface


 class RunnableThread implements Runnable{
  Thread t;
  String s=null;

  RunnableThread(String s1){
  t=new Thread(this);
  public void run(){


public class RunnableThreadExample{
  public static void main(String args[]){
  RunnableThread m1=new RunnableThread("Thread started....");

Output :

When you will execute both, RunThread.java and RunnableThreadExample.java one by one you will get the same output.

Download Source Code



Liked it!  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.

Posted on: June 25, 2013

Ask Questions?    Discuss: What Is Thread In Java?  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image