Java多线程代码示例

package algorithm;


class Mythread extends Thread{
    String name;
    public Mythread(String name){
        this.name=name;
    }
    
    public void run(){
        System.out.println(name+":step1");
        System.out.println(name+":step2");
        System.out.println(name+":step3");
    }
}

class Mythread1 implements Runnable{
    String name;
    Mythread1(String name){
        this.name=name;
    }
    public void run(){
        System.out.println(name+":step1");
        System.out.println(name+":step2");
        System.out.println(name+":step3");
    }
}

public class Thread1 {

    public static void main(String[] args) {
/*        Mythread a = new Mythread("a");
        Mythread b = new Mythread("b");
        Mythread c = new Mythread("c");
        a.start();
        b.start();
        c.start();*/
        Mythread1 a = new Mythread1("a"); 
        Mythread1 b = new Mythread1("b"); 
        Mythread1 c = new Mythread1("c"); 
        Thread t1 = new Thread(a);
        Thread t2 = new Thread(b);
        Thread t3 = new Thread(c);
        t1.start();
        t2.start();
        t3.start();
    }
}

 

posted @ 2016-04-20 10:40  finalboss1987  阅读(190)  评论(0编辑  收藏  举报