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);
    }
}
posted @ 2015-07-15 15:49  cuiz_book  阅读(186)  评论(0编辑  收藏  举报