其他分享
首页 > 其他分享> > 多线程

多线程

作者:互联网

线程状态

package com.company.demo.test;

public class Demo10_state {

    public static void main(String[] args) {

//        里面写的是run方法,使得线程能维持一段时间
        Thread thread = new Thread(() -> {
            try {
                Thread.sleep(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("**************");
        });

        System.out.println(thread.getState());//NEW

        thread.start();
        System.out.println(thread.getState()); //RUNNABLE

        while (thread.getState() != Thread.State.TERMINATED) {
            try {
                thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程状态:"+thread.getState());
        }
        System.out.println("**************");
        System.out.println(thread.getState());
    }
}

在这里插入图片描述

标签:getState,Thread,thread,System,println,多线程,out
来源: https://blog.51cto.com/u_15202146/2777534