Daobin's Den


Hello,我是稻草人 (@daobin), Java / Js 开发者一名, 现居杭州。漫漫修行路, 吾将上下求索


线程和进程

看到一个关于线程状态的问题:

有一个4*50的二维数组,用4个线程去分5个阶段去填满它,也就说,第一阶段大家一起填0-9,当大家都填满了0-9,再一起去填10-19,以此类推,先填满的线程要等着其他线程都填好了,再继续。

线程和进程

进程就是一个程序的执行流程,内部保存程序运行所需的资源,所以是系统资源调度和分配的最小单位。 线程是系统分配处理器时间的基本单元,或者说进程之内独立执行的一个单元执行流。是程序执行的最小单位。

线程的状态

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;
}

状态间变化

policy_state_machine

项目

Github地址

最近的文章

Jenkins Pipeline实例

Jenkins 多分支流水线Jenkins 流水线是一套插件,它支持实现和集成持续交付流水线到 Jenkins。流水线提供了一组可扩展的工具,用于通过流水线 DSL 将简单到复杂的交付流水线建模为“代码”。1、什么是 pipelinepipeline 是 jenkins 的一套插件,用于定义 CD 流程,弹性,可管理。2、什么是 Jenkinsfile通过代码的方式来管理 pipeline这样一来,可以通过版本控制系统来管理。3、Jenkinsfile 的内容示例#!/usr/bin/en...…

Pipeline继续阅读
更早的文章

微信开发

介绍 微信相关开发包括:公众号开发、小程序开发、微信支付。公众号又有服务号、订阅号、企业号的区别,从开发上无非是微信功能开放多少问题,技术实现区别不大。微易保箱是一个服务号,实现了C端用户订单、保单的部分功能。技术栈 Spring这一套 ORM-数据库持久层框架用了Mybatis,个人比较喜欢直接写原生SQL的开发模式 前端Vue2.0交互模式公众号交互模式是 用户、微信服务器、公众号服务器之间发生的信息交换、请求,如下图:发生信息交互的时候,以用户的openId作为唯一标识。同一...…

Wechat继续阅读