Java中的多线程

实现类:

public class hello implements Runnable  {
    private String name;
    
    hello(){    };
    hello(String name){
        this.name = name;
    }
    public void run() {
        for (int i = 0; i < 10000; i++) {
            System.out.println(name+" Run "+i);
        }

}

 

使用:

    public static void main(String[] args) {
        hello h1 = new hello("多线程A");
        Thread t1 = new Thread(h1);
        hello h2 = new hello("多线程B");
        Thread t2 = new Thread(h2);
        t1.start();
        t2.start();
    }

结果:

 

 

可以看出 A,B是同时进行的。

 

posted @ 2012-08-28 21:15  LLLeon  阅读(99)  评论(0编辑  收藏  举报