zoukankan      html  css  js  c++  java
  • Java并发编程--线程的生命周期

    在 Java 中线程的生命周期中一共有 6 种状态。

    1. NEW

    Thread state for a thread which has not yet started.
    新建状态,线程被创建出来,但尚未启动时的线程状态。

    2. RUNNABLE

    A thread in the runnable state is executing in the Java virtual machine but it may be waiting for other resources from the operating system such as processor.
    就绪状态,表示可以运行的线程状态,它可能正在运行,或者是在排队等待操作系统给它分配 CPU 资源。

    3. BLOCKED

    Thread state for a thread blocked waiting for a monitor lock.

    A thread in the blocked state is waiting for a monitor lock to enter a synchronized block/method or reenter a synchronized block/method after calling {Object#wait()}.

    4. WAITING

    A thread is in the waiting state due to calling one of the following methods:

    • Object#wait() with no timeout
    • Thread#join() with no timeout
    • LockSupport#park()

    A thread in the waiting state is waiting for another thread to perform a particular action.

    For example, a thread that has called Object.wait() on an object is waiting for another thread to call Object.notify() or Object.notifyAll() on that object.

    A thread that has called Thread.join() is waiting for a specified thread to terminate.

    5. TIMED_WAITING

    Thread state for a waiting thread with a specified waiting time.

    A thread is in the timed waiting state due to calling one of the following methods with a specified positive waiting time:

    • Thread#sleep(long)
    • Object#wait(long) with timeout
    • Thread#join(long) with timeout
    • LockSupport#parkNanos
    • LockSupport#parkUntil

    6. TERMINATED

    The thread has completed execution.

    6种状态的流转如下图:

  • 相关阅读:
    1210 BBS admin后台管理及侧边栏筛选个人站点
    1209 BBS 登录
    更换 npm 源国内镜像 cnpm
    Linux软件管理
    apt-get / yum 软件安装源(国内)
    修改pip源为国内镜像源(加速下载)
    修改浏览器搜索引擎:网址应该如何填写
    如何根据实际问题选择一个合适的数学模型
    安装向量和矩阵运算库函数
    配置编译器(GCC和GFortran)
  • 原文地址:https://www.cnblogs.com/xxoome/p/13280772.html
Copyright © 2011-2022 走看看