【内核线程】Java线程与内核线程区别

线程状态转换

  以下为大部分操作系统给出的线程状态,但和java的线程状态不是一回事,java是封装了操作系统线程状态的

JVM线程模型

  要注意:

  • 系统进行IO的时候,系统线程是属于阻塞状态等待中断发生的,而JVM线程体现出来的状态是Runnable
  • JVM中,Runnable状态包括系统线程的runnable和running状态
 /**
     * A thread state.  A thread can be in one of the following states:
     * <ul>
     * <li>{@link #NEW}<br>
     *     A thread that has not yet started is in this state.
     *     </li>
     * <li>{@link #RUNNABLE}<br>
     *     A thread executing in the Java virtual machine is in this state.
     *     </li>
     * <li>{@link #BLOCKED}<br>
     *     A thread that is blocked waiting for a monitor lock
     *     is in this state.
     *     </li>
     * <li>{@link #WAITING}<br>
     *     A thread that is waiting indefinitely for another thread to
     *     perform a particular action is in this state.
     *     </li>
     * <li>{@link #TIMED_WAITING}<br>
     *     A thread that is waiting for another thread to perform an action
     *     for up to a specified waiting time is in this state.
     *     </li>
     * <li>{@link #TERMINATED}<br>
     *     A thread that has exited is in this state.
     *     </li>
     * </ul>
     *
     * <p>
     * A thread can be in only one state at a given point in time.
     * These states are virtual machine states which do not reflect
     * any operating system thread states.
     *
     * @since   1.5
     * @see #getState
     */
    public enum State {
        /**
         * Thread state for a thread which has not yet started.
         */
        NEW,

        /**
         * Thread state for a runnable thread.  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.
         */
        RUNNABLE,

        /**
         * 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
         * {@link Object#wait() Object.wait}.
         */
        BLOCKED,

        /**
         * Thread state for a waiting thread.
         * A thread is in the waiting state due to calling one of the
         * following methods:
         * <ul>
         *   <li>{@link Object#wait() Object.wait} with no timeout</li>
         *   <li>{@link #join() Thread.join} with no timeout</li>
         *   <li>{@link LockSupport#park() LockSupport.park}</li>
         * </ul>
         *
         * <p>A thread in the waiting state is waiting for another thread to
         * perform a particular action.
         *
         * For example, a thread that has called <tt>Object.wait()</tt>
         * on an object is waiting for another thread to call
         * <tt>Object.notify()</tt> or <tt>Object.notifyAll()</tt> on
         * that object. A thread that has called <tt>Thread.join()</tt>
         * is waiting for a specified thread to terminate.
         */
        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:
         * <ul>
         *   <li>{@link #sleep Thread.sleep}</li>
         *   <li>{@link Object#wait(long) Object.wait} with timeout</li>
         *   <li>{@link #join(long) Thread.join} with timeout</li>
         *   <li>{@link LockSupport#parkNanos LockSupport.parkNanos}</li>
         *   <li>{@link LockSupport#parkUntil LockSupport.parkUntil}</li>
         * </ul>
         */
        TIMED_WAITING,

        /**
         * Thread state for a terminated thread.
         * The thread has completed execution.
         */
        TERMINATED;
    }

原文地址:https://www.cnblogs.com/iCanhua/p/12556258.html

时间: 2024-08-28 09:34:33

【内核线程】Java线程与内核线程区别的相关文章

Java中的守护线程

Java中的守护线程 Java中的守护线程与UNIX中的守护线程概念不同,UNIX中的守护线程相当于一项服务,一直运行在后台,而Java中的守护线程是这样定义的: A daemon thread is a thread, that does not prevent the JVM from exiting when the program finishes but the thread is still running. 也就是说,当程序中只有守护线程时,JVM就会自动退出,典型的守护线程就是垃

C++windows内核编程笔记day13 进程、线程与信号量

Windows进程 进程是一个容器,包含程序执行需要的代码.数据.资源等信息, windows进程的特点: 每个进程都有自己的ID号 每个进程都有自己的地址空间,进程之间无法访问对方的地址空间. 每个进程都有自己的安全属性 每个进程至少包含一个线程. 获取和释放环境信息 GetEnvironmentStrings FreeEnvironmentStrings 获取或设置 本程序的环境变量 GetEnvironmentVariable SetEnvironmentVariable 示例: char

【转】linux 用户线程、LWP、内核线程学习笔记

[好文转发---linux 用户线程.LWP.内核线程学习笔记] 在现代操作系统中,进程支持多线程.进程是资源管理的最小单元:而线程是程序执行的最小单元.一个进程的组成实体可以分为两大部分:线程集合资源集.进程中的线程是动态的对象:代表了进程指令的执行.资源,包括地址空间.打开的文件.用户信息等等,由进程内的线程共享. 线程有自己的私有数据:程序计数器,栈空间以及寄存器. Why Thread?(传统单线程进程的缺点) 1. 现实中有很多需要并发处理的任务,如数据库的服务器端.网络服务器.大容量

Java实现线程的三种方式和区别

Java实现线程的三种方式和区别 Java实现线程的三种方式: 继承Thread 实现Runnable接口 实现Callable接口 区别: 第一种方式继承Thread就不能继承其他类了,后面两种可以: 使用后两种方式可以多个线程共享一个target: Callable比Runnable多一个返回值,并且call()方法可以抛出异常: 访问线程名,第一种直接使用this.getName(),后两种使用Thread.currentThread().getName(). 下面我们通过代码来看一下实现

java中创建线程的三种方法以及区别

Java使用Thread类代表线程,所有的线程对象都必须是Thread类或其子类的实例.Java可以用三种方式来创建线程,如下所示: 1)继承Thread类创建线程 2)实现Runnable接口创建线程 3)使用Callable和Future创建线程 下面让我们分别来看看这三种创建线程的方法. ------------------------继承Thread类创建线程--------------------- 通过继承Thread类来创建并启动多线程的一般步骤如下 1]d定义Thread类的子类

linux内核——进程,轻量级进程,线程,线程组

1.进程.轻量级进程.线程.线程组之间的关系 2.及它们的标识相关说明 一.进程.轻量级进程.线程.线程组之间的关系 借助上图说明: 进程P0有四条执行流,即线程, 主线程t0是它的第一个线程,且与进程P0相关联, 之后衍生出t1.t2.t3三个线程,这三个线程与轻量级进程P1.P2.P3一一关联, 所有的进程.轻量级进程.线程组成了线程组. 轻量级进程也是进程,只不过它与某进程的某特定线程相关联. 二.它们的标识相关说明 pid是进程标识符,tgid是线程组标识符 每个进程都有自己的pid,如

jvm(12)-java内存模型与线程

[0]README 0.1)本文部分文字描述转自“深入理解jvm”,旨在学习“java内存模型与线程” 的基础知识: [1]概述 1)并发处理的广泛应用是使得 Amdahl 定律代替摩尔定律称为计算机性能发展源动力的根本原因: 2)Amdahl 定律:该定律通过系统中并行化与串行化的比重来描述多处理器系统能获得的运算加速能力: 3)摩尔定律:该定律用于描述处理器晶体管数量与运行效率间的发展关系: Conclusion)这两个定律的更替代表了近年来硬件发展从追求处理器频率到追求多核心并行处理的发展

java内存模型与线程(转) good

java内存模型与线程 参考 http://baike.baidu.com/view/8657411.htm http://developer.51cto.com/art/201309/410971_all.htm http://www.cnblogs.com/skywang12345/p/3447546.html 计算机的CPU计算能力超强,其计算速度与 内存等存储 和通讯子系统的速度相比快了几个数量级, 数据加载到内存中后,cpu处理器运算处理时,大部分时间花在等待获取去获取磁盘IO.网络通

Java内存模型与线程

写在前面:与之前主流程序语言(c/c++等)直接使用物理硬件和操作系统的内存模型不同,java虚拟机为了屏蔽各种硬件和操作系统的内存访问差异定义了一种java内存模型.其主要定义程序中各个变量的访问规则(在虚拟机中将变量存储到内存和从内存中取出变量的底层细节). 线程.主内存.工作内存之间的交互关系 1.java内存模型结构: -所有的变量都存储在主内存中. -每条线程还有自己的工作内存. -工作内存中保存了从主内存中拷贝的该线程所要使用到的变量 -每条线程对变量的操作必须在自己的工作内存中,不

进程与线程的定义、关系及区别

进程与线程的定义.关系及区别     --参考博客文章:http://blog.csdn.net/yanxiaolx/article/details/51763372 一.进程的定义 进程:指在系统中能独立运行并作为资源分配的基本单位,它是由一组机器指令.数据和堆栈等组成的,是一个能独立运行的活动实体. 进程一般有三个状态:就绪状态.执行状态和等待状态[或称阻塞状态]:进程只能由父进程建立,系统中所有的进程形成一种进程树的层次体系:挂起命令可由进程自己和其他进程发出,但是解除挂起命令只能由其他进