个人简介

Echo Blog


江湖无名 安心练剑
  • 轻松学习多线程 04-线程间的协作及状态迁移 wait notify
    状态迁移图 常言道,一图胜千言。 线程协作 我们前面讲到使用 synchronized 进行线程间的互斥。 但,如果我们需要更加精确地控制。比如: 如果空间为空则写入,如果非空则一直等待。 空间已经为空时,“通知”其他等待的线程。 为此,JDK 为我们准备了 wait()、notify()、notifyAll() 等方法,用于线程的...
    2019-01-19 03:21:15 | Thread
  • 轻松学习多线程 03-多线程的同步与锁
    问题的出现 上代码 public class Num { private int num; public int getNum() { return num; } public int add(int num) { this.num += num; return this.num; } } 测...
    2019-01-19 03:21:15 | Thread
  • 轻松学习多线程 02-thread 源码分析
    前言 最近想写一个多线程的程序,发现对于 java 的多线程理解还是不够深入。 所以看下源码,学习下基础知识。 接口 作用 接口作为绝对的抽象,非常便于后期拓展。 核心接口 Runnable.java public interface Runnable { /** * When an object implementing interface <...
    2019-01-19 03:21:15 | Thread
  • 轻松学习多线程 02-多线程的基本机制
    定义线程 实现线程的方式,上一章中已经提到。下面使用实现Runnable的方式 /** * Created by 侯彬彬 on 2016/4/14. */ public class NumCounter implements Runnable { private static int count = 0; private final int id = coun...
    2019-01-19 03:21:15 | Thread
  • 轻松学习多线程 01-多线程是什么
    线程的概念 线程 是程序中的执行线程。Java 虚拟机允许应用程序并发地运行多个执行线程。 每个线程都有一个优先级,高优先级线程的执行优先于低优先级线程。每个线程都可以或不可以标记为一个守护程序。当某个线程中运行的代码创建一个新 Thread 对象时,该新线程的初始优先级被设定为创建线程的优先级,并且当且仅当创建线程是守护线程时,新线程才是守护程序。 当 Java 虚拟机启动时,通常都会...
    2019-01-19 03:21:15 | Thread
  • 轻松学习多线程 01-多线程入门基础知识
    Thread In concurrent programming, there are two basic units of execution: processes and threads. A process has a self-contained execution environment. Threads are sometimes called lightweight proc...
    2019-01-19 03:21:15 | Thread
  • 轻松学习多线程 01-多线程进阶
    Guarded Blocks Threads often have to coordinate their actions. The most common coordination idiom is the guarded block. Such a block begins by polling a condition that must be true before the bloc...
    2019-01-19 03:21:15 | Thread
  • 轻松学习多线程 00-多线程学习概览
    基础知识 下面是一些关于 java 线程的基础知识博客。 需要补充知识的可以浏览一下,已经熟悉的可以直接跳过。 系列目录 线程-001-线程简介 线程-002-基本的线程机制 线程-003-线程的同步与锁 线程-004-线程间的协作及状态迁移 轻松学习多线程-00-序章 轻松学习多线程-01-基础知识 轻松学习多线程-02-Single Threaded Executio...
    2019-01-19 03:21:15 | Thread