美文网首页
调试多线程

调试多线程

作者: 少寨主的互联网洞察 | 来源:发表于2019-02-17 19:59 被阅读0次

    一段简单多线程代码:

    public class MultiThread implements Runnable{
        static MultiThread instance=new MultiThread();
        @Override
        public void run() {
            synchronized (this){
                System.out.println("我叫: "+Thread.currentThread().getName());
                try {
                    Thread.sleep(3000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"运行结束");
            }
        }
    
        public static void main(String[] args) {
            Thread t1=new Thread(instance);
            Thread t2=new Thread(instance);
            t1.start();
            t2.start();
            while(t1.isAlive()|| t2.isAlive()){
    
            }
            System.out.println("主线程运行结束");
        }
    }
    
    

    打个断点

    image.png
    切换为如图并点击
    image.png
    执行如下语句
    image.png
    可查看线程状态

    相关文章

      网友评论

          本文标题:调试多线程

          本文链接:https://www.haomeiwen.com/subject/yqlneqtx.html