0
点赞
收藏
分享

微信扫一扫

ThreadDemo2


package com.shrimpking.t1;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2024/9/21 16:26
 */
class TestThread2 extends Thread{
    @Override
    public void run()
    {
        for (int i = 0; i < 5; i++)
        {
            System.out.println("TestThread is running");
            try
            {
                Thread.sleep(1000);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }

    }
}

//ch15-2 多线程
public class ThreadDemo2
{
    public static void main(String[] args)
    {
        new TestThread2().start(); //激活线程

        for (int i = 0; i < 5; i++)
        {
            System.out.println("main线程在运行");
            try
            {
                //休眠1秒
                Thread.sleep(1000);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }

    }
}

举报

相关推荐

2020/2/22-2

javase 2-2 类

单链表2-2

技术2---swagger2

2

0 条评论