Multi Threading

copy ,compile and run the following example


  Compile >>javac   Appl_7.java
the output will be Appl_7.class   which is the byte code format portable can be run 
in any platform OS

  run     >>java Appl_7 
You invoke the interpreter (JVM) to run the Appl_7.class





/*
        Author:ZT
        Date   : Jun 26,2017
        Reference: Java Oracle J2SE  

*/


package a.b.c;



import java.awt.*;

import javax.swing.*;




class  Appl_7 {


	Appl_7(String names){


		
		 // thrd.start();

	}  // constructor



	public static void main(String args[]){


		mythread();
		mythread1();


	}  // edn of main() method

	public static void mythread(){

		
		// System.out.println("Welocoem ...");
		Mythread  thrd=new Mythread("Dubai");
		//thrd.run();
		try{
		 Thread.sleep(5000);
		}catch(Exception ex1){

			JOptionPane.showMessageDialog(null,ex1.getMessage());

		}

		Mythread  thrd2=new Mythread("Sharjh");
		try{
		 Thread.sleep(5000);
		}catch(Exception ex2){

			JOptionPane.showMessageDialog(null,ex2.getMessage());

		}
		Mythread  thrd3=new Mythread("Ajman");
		try{
		 Thread.sleep(5000);
		}catch(Exception ex3){

			JOptionPane.showMessageDialog(null,ex3.getMessage());

		}
		Mythread  thrd4=new Mythread("Fujerah");



		//thrd1.run();

	}  // end of Mythread
////////////////////////////////

	public static void mythread1(){

		
		// System.out.println("Welocoem ...");
		Mythread1  thrd=new Mythread1("Kuwait");
		//thrd.run();
		try{
		 Thread.sleep(5000);
		}catch(Exception ex1){

			JOptionPane.showMessageDialog(null,ex1.getMessage());

		}

		Mythread1  thrd2=new Mythread1("Qatar");
		try{
		 Thread.sleep(5000);
		}catch(Exception ex2){

			JOptionPane.showMessageDialog(null,ex2.getMessage());

		}
		Mythread1  thrd3=new Mythread1("Bahrain");
		try{
		 Thread.sleep(5000);
		}catch(Exception ex3){

			JOptionPane.showMessageDialog(null,ex3.getMessage());

		}
		Mythread1  thrd4=new Mythread1("SA");



		//thrd1.run();


	} // end of mythread1




}  // end of class Appl_7




class Mythread implements Runnable{

	Thread thred;
	String mystr1;

	Mythread(String str1){

		 thred=new Thread(this,str1);
		 thred.start();

	}  // Constructor



	  public void start(){


		 // Mythread  thrd=new Mythread(mystr1);
		  //thrd.run();


	  }  // end of start()



	public void run(){


	try{

	for(int i=0;i<5;i++){

	
		System.out.println(thred.getName()+"............>"+ i);

		Thread.sleep(5000);

	}

	}catch(Exception  ex){


		JOptionPane.showMessageDialog(null,ex.getMessage());


	}


	}  // end of Run





}  // end of class Mythread





class Mythread1 implements Runnable{

	Thread thred;
	String mystr1;

	Mythread1(String str1){

		 thred=new Thread(this,str1);
		 thred.start();

	}  // Constructor



	  public void start(){


		 // Mythread  thrd=new Mythread(mystr1);
		  //thrd.run();


	  }  // end of start()



	public void run(){


	try{

	for(int i=0;i<5;i++){

	
		System.out.println(thred.getName()+"............>>>>"+ i);

		Thread.sleep(5000);

	}

	}catch(Exception  ex){


		JOptionPane.showMessageDialog(null,ex.getMessage());


	}


	}  // end of Run





}  // end of class Mythread1