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种状态的流转如下图:

  • 相关阅读:
    MAVEN 安装与配置
    MAVEN 常用仓库地址
    一些常用的工具
    springFramework 源码学习之源码下载与编译
    测试工程师学习笔记
    什么是多态
    聚簇索引与非聚簇索引
    正则表达式菜鸟教程
    我的第一篇博客
    转Hibernate继承
  • 原文地址:https://www.cnblogs.com/xxoome/p/13280772.html
Copyright © 2011-2022 走看看