Lev1

导航

继承Thread类的方式创建多线程

 

package MoreThread;

public class MoreThread implements Runnable{

    @Override
    public void run() {
        for(int i = 0;i < 20;i++ ) {
            System.out.println();
            
            String name = Thread.currentThread().getName();
            System.out.println((i+1)+".你好,来自线程"+name);
            
        }
        
    }

}
package MoreThread;

public class Main {
    public static void main(String[] args) {
        MoreThread mt = new MoreThread();
        Thread l1 = new Thread(mt);
        Thread l2 = new Thread(mt);
        l1.start();
        l2.start();
    }
}

 

posted on 2019-08-05 22:52  Lev1  阅读(469)  评论(0编辑  收藏  举报