0
点赞
收藏
分享

微信扫一扫

110.Thread.sleep(1000);

爱奔跑的读书者 2022-04-26 阅读 32
package com.itheima.threaddemo6;

public class MyRunnable implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"----"+i);

        }
    }
}
package com.itheima.threaddemo6;

public class Demo {
    public static void main(String[] args) throws InterruptedException {
       /* System.out.println("睡觉前");
        Thread.sleep(3000);
        System.out.println("睡醒了");*/
        MyRunnable mr=new MyRunnable();
        Thread t1=new Thread(mr);
        Thread t2=new Thread(mr);
        t1.start();
        t2.start();
    }
}
举报

相关推荐

0 条评论