Multithreading Example in Java

package multithreading;
import java.io.*;
public class Multithreading 
{
    public static void main(String[] args) 
    {
                mthread thread1 = new mthread("piit");
		mthread thread2 = new mthread("new panvel");
		thread1.start();
		thread2.start();
    }
}
class mthread extends Thread
{
    String a;
    public void run() 
	{
		for(int i=0;i<=3;i++)
                {
			System.out.println("  "+a);
                        try
                        {
                            Thread.sleep(500);
                        }catch(Exception e){};
                }
	}
	mthread(String b)
	{
		a=b;
	}
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.