Java基础--多线程--第一例

/**

 * 

 */

package com.train;



public class MThreadTest {



    public static void main(String[] args) {

        

        Thread1 thd = new Thread1();

        thd.start();

        

        for(int i = 0;i<100;i++)

        System.out.println("main Thread--"+i);

        

        

        

    }

}



class Thread1 extends Thread{

    public void run(){

        for(int i = 0;i<10;i++)

        System.out.println("hello Thread1! +++++++++++++"+i);

    }

}

::

image

 

-------------------------

/**

 * 

 */

package com.train;



public class MThreadTest{



    public static void main(String[] args){

        

        Thread1 thd1 = new Thread1("thd-first");

        Thread1 thd2 = new Thread1("thd-second");

        thd1.start();

        thd2.start();

        

        for(int i = 0;i<10;i++)

        System.out.println("main Thread--"+i);

        

    }

}



class Thread1 extends Thread{

     

    Thread1(String arg){

        super(arg); 

        

    }

    

    //override

    public void run(){

        

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

        System.out.println(this.getName()+" run ----------"+i);

    }

}

你可能感兴趣的:(java基础)