Ref:  Java 6 Thread States and Life Cycle

This is an example of UML protocol state machine diagram showing thread states and thread life cycle for the Thread class in Java 6.

Thread is a lightweight process, the smallest unit of scheduled execution. Instance of the Thread class in Java 6 could be in one of the following states:

  • new,
  • runnable,
  • timed waiting,
  • waiting,
  • blocked,
  • terminated.

These states are Java Virtual Machine (JVM) states reported by JVM to Java programs. At any given point in time thread could be in only one state.

  

Protocol state machine example - Thread states and life cycle in Java 6

New is the thread state for a thread which was created but has not yet started.

At the lower operating system (OS) level, JVM’s runnable state could be considered as a composite state with two substates. When a thread transitions to the runnable JVM state, the thread first goes into the ready substate. Thread scheduling decides when the thread could actually start, proceed or be suspended. Thread.yield() is explicit recommendation to thread scheduler to pause the currently executing thread to allow some other thread to execute.

A thread in the runnable state is executing from the JVM point of view but in fact it may be waiting for some resources from the operating system.

Timed waiting is a thread state for a thread waiting 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(sleeptime)
  • Object.wait(timeout)
  • Thread.join(timeout)
  • LockSupport.parkNanos(timeout)
  • LockSupport.parkUntil(timeout)

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

  • Object.wait()
  • Thread.join()
  • LockSupport.park()

Note, that 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. It means that waiting state could be made a composite state with states corresponding to these specific conditions.

Thread is in the blocked state while waiting for the monitor lock to enter a synchronized block or method or to reenter a synchronized block or method after calling Object.wait().

A synchronized statement or method acquires a mutual-exclusion lock on behalf of the executing thread, executes a block or method, and then releases the lock. While the executing thread owns the lock, no other thread may acquire the lock and is blocked waiting for the lock.

After thread has completed execution of run() method, it is moved into terminated state.

Java 6 Thread States and Life Cycle.的更多相关文章

  1. Life Cycle of Thread – Understanding Thread States in Java

    Life Cycle of Thread – Understanding Thread States in Java 深入理解java线程生命周期. Understanding Life Cycle ...

  2. [Java多线程]-Thread和Runable源码解析

    多线程:(百度百科借一波定义) 多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提 ...

  3. java 线程 Thread 使用介绍,包含wait(),notifyAll() 等函数使用介绍

    (原创,转载请说明出处!谢谢--http://www.cnblogs.com/linguanh/) 此文目的为了帮助大家较全面.通俗地了解线程 Thread 相关基础知识! 目录: --线程的创建: ...

  4. General Thread States

    对于实践中可能出现的各种General Thread States 以下列表描述了与常规查询处理关联的线程状态值,而不是更复杂的活动,例如复制. 其中许多仅用于在服务器中查找错误. after cre ...

  5. 对java的Thread的理解

    最好不适用线程的子线程,直接调用线程,然后用rannable接口 然后如果要公用一个参数,就是公用资源的时候,一定要在run方法的前面加上synchronized 例子 猫和狗喝同一杯水(共用资源的问 ...

  6. Java线程Thread的状态解析以及状态转换分析 多线程中篇(七)

    线程与操作系统中线程(进程)的概念同根同源,尽管千差万别. 操作系统中有状态以及状态的切换,Java线程中照样也有. State 在Thread类中有内部类 枚举State,用于抽象描述Java线程的 ...

  7. 转载:java中Thread.sleep()函数使用

    点我跳过黑哥的卑鄙广告行为,进入正文. Java多线程系列更新中~ 正式篇: Java多线程(一) 什么是线程 Java多线程(二)关于多线程的CPU密集型和IO密集型这件事 Java多线程(三)如何 ...

  8. 线上zk节点报org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:187) at java.lang.Thread.run(libgcj.so.10)

    线上zk做配置管理,最近突然发现两个节点一直在刷下边 java.nio.channels.CancelledKeyException    at gnu.java.nio.SelectionKeyIm ...

  9. Java并发--Thread类详情

    以下是本文的目录大纲: 一.线程的状态 二.上下文切换 三.Thread类中的方法 转载原文链接:http://www.cnblogs.com/dolphin0520/p/3920357.html 一 ...

随机推荐

  1. 如何利用服务器下发的Cookie实现基于此Cookie的会话保持

    Cookie是一种在客户端保持HTTP状态信息的常用技术,基于Cookie的会话保持常常出现在很多AX的部署案例中,尤其是涉及电子交易的系统部署中.此类系统往往要求负载均衡设备按照服务器下发的Cook ...

  2. activiti入门2流程引擎的API和服务基础

      RepositoryService : 管理和控制发布包和流程定义(包含了一个流程每个环节的结构和行为)的操作 除此之外,服务可以 查询引擎中的发布包和流程定义. 暂停或激活发布包,对应全部和特定 ...

  3. mysql grant 示例

    ' with grant option; FLUSH PRIVILEGES;

  4. ASP.NET 中Request.QueryString 中的key

    在ASP.net中 的Key是可能为null的,例如在如下的Url中 http://localhost:14546/Home/Index?a 有一个key=null 其value是a,以前一直以为ke ...

  5. 利用python分析nginx日志

    最近在学习python,写了个脚本分析nginx日志,练练手.写得比较粗糙,但基本功能可以实现. 脚本功能:查找出当天访问次数前十位的IP,并获取该IP来源,并将分析结果发送邮件到指定邮箱. 实现前两 ...

  6. Myeclipse 保存jsp异常Save FailedCompilation unit name must end with .java, or one of the registered Java-like extensions

    如图 解决方法:去掉jsp页面的调试断点

  7. HDOJ/HDU 2555 人人都能参加第30届校田径运动会了(判断加排序~)

    Problem Description 杭州师范大学第29届田径运动会圆满的闭幕了,本届运动会是我校规模最大,参赛人数最多的一次运动会.在两天半时间里,由学生.教工组成的61支代表队共2664名运动员 ...

  8. 折腾iPhone的生活——iPhone 5s 开启 assistive touch 后卡顿的问题

    刚刚入手我的国行iPhone5s土狗灰,感觉倍棒~ 但是一上手就发现了一个问题:卡顿. 卡顿不仅体现在日常使用中,游戏中更加严重,当我玩水果忍者的时候,会发现切水果的画面都变得不流畅起来,这是拥有64 ...

  9. ubuntu制作usb启动盘

    准备: u盘 iso镜像文件--ubuntu-12.04.2-desktop-amd64.iso 烧盘软件--unetbootin-linux-583 步骤: 格式化u盘 查看u盘信息 #mount/ ...

  10. IOS性能调优系列:Analyze静态分析

    目前关于IOS性能优化的教程较少,决定写一个<IOS性能调优系列>,主要关注与内存泄漏.性能优化.流量和电量分析几个方面. XCode已经提供了非常强大的性能调优工具,结合几个第三方工具和 ...