多线程03 用runnable接口来实现

MyRunnable类

点击查看代码
package it_06;

public class MyRunnable implements Runnable{
    @Override
    public void run() {
        for(int i=0;i<100;i++){
            System.out.println(Thread.currentThread().getName()+": "+i);
        }
    }
}

main
点击查看代码
package it_06;

public class Demo9 {
    public static void main(String[] args) {
        MyRunnable mr = new MyRunnable();

        Thread t1 =new Thread(mr,"A");
        Thread t2 =new Thread(mr,"B");

        t1.start();
        t2.start();
    }
}

posted @ 2025-04-25 20:39  lfqyj  阅读(1)  评论(0)    收藏  举报