Runnable:

@FunctionalInterface
public interface Runnable {
/**
* When an object implementing interface <code>Runnable</code> is used
* to create a thread, starting the thread causes the object's
* <code>run</code> method to be called in that separately executing
* thread.
* <p>
* The general contract of the method <code>run</code> is that it may
* take any action whatsoever.
*
* @see java.lang.Thread#run()
*/
public abstract void run();
}

Runnable是个只有一个方法的接口。 
Thread:

public
class Thread implements Runnable {
/* What will be run. */
private Runnable target;
/**
* If this thread was constructed using a separate
* <code>Runnable</code> run object, then that
* <code>Runnable</code> object's <code>run</code> method is called;
* otherwise, this method does nothing and returns.
* <p>
* Subclasses of <code>Thread</code> should override this method.
*
* @see #start()
* @see #stop()
* @see #Thread(ThreadGroup, Runnable, String)
*/
@Override
public void run() {
if (target != null) {
target.run();
}
}
}

Thread实现了Runnable接口,而且还组合了一个Runnable,可以看出,实现的方法内部是调用组合类的方法,这其实就是装饰模式。

多线程-Thread与Runnable源码分析的更多相关文章

  1. java多线程系列(九)---ArrayBlockingQueue源码分析

    java多线程系列(九)---ArrayBlockingQueue源码分析 目录 认识cpu.核心与线程 java多线程系列(一)之java多线程技能 java多线程系列(二)之对象变量的并发访问 j ...

  2. java多线程系列:ThreadPoolExecutor源码分析

    前言 这篇主要讲述ThreadPoolExecutor的源码分析,贯穿类的创建.任务的添加到线程池的关闭整个流程,让你知其然所以然.希望你可以通过本篇博文知道ThreadPoolExecutor是怎么 ...

  3. Java多线程学习之ThreadLocal源码分析

    0.概述 ThreadLocal,即线程本地变量,是一个以ThreadLocal对象为键.任意对象为值的存储结构.它可以将变量绑定到特定的线程上,使每个线程都拥有改变量的一个拷贝,各线程相同变量间互不 ...

  4. [Java多线程]-Thread和Runable源码解析之基本方法的运用实例

    前面的文章:多线程爬坑之路-学习多线程需要来了解哪些东西?(concurrent并发包的数据结构和线程池,Locks锁,Atomic原子类) 多线程爬坑之路-Thread和Runable源码解析 前面 ...

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

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

  6. 多线程十之CopyOnWriteArrayList源码分析

    目录 简介 类结构 源码解析 构造方法 add(E e) add(int index, E element) get(int index) remove(int index) 迭代器Iterator遍 ...

  7. java.lang.Runnable 源码分析

    子接口:RunnableFuture<V>, RunnableScheduledFuture<V> 实现类:AsyncBoxView.ChildState, ForkJoinW ...

  8. [源码分析] 并行分布式任务队列 Celery 之 Timer & Heartbeat

    [源码分析] 并行分布式任务队列 Celery 之 Timer & Heartbeat 目录 [源码分析] 并行分布式任务队列 Celery 之 Timer & Heartbeat 0 ...

  9. Memcached源码分析

    作者:Calix,转载请注明出处:http://calixwu.com 最近研究了一下memcached的源码,在这里系统总结了一下笔记和理解,写了几 篇源码分析和大家分享,整个系列分为“结构篇”和“ ...

随机推荐

  1. HDU 4662 MU Puzzle (2013多校6 1008 水题)

    MU Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. SQL Server 2012的内部原理和故障排除(50):Burgess_Liu的专栏

    http://blog.csdn.net/Burgess_Liu/article/category/1821435/2 http://www.cnblogs.com/fygh/archive/2012 ...

  3. 【JSTL】<c:if test=“”>没有else的解决方法

    后台封装了一个对象 放在model里: model.addAttribute("notice", notice); notice是个对象 然后前台如果没有公告的话,希望显示暂无公告 ...

  4. 事件click,bind,click

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  5. DEBUG : Eclipse Debug 时出现 Cannot connect to VM select failed错误

    Eclipse在执行Debug操作时, 出现“Eclipse Debug 时出现 "Cannot connect to VM select failed"”错误, 在网上查找该错误 ...

  6. LINUX提权后获取敏感信息之方法

    文中的每行为一条命令,文中有的命令可能在你的主机上敲不出来,因为它可能是在其他版本的linux中所使用的命令. 列举关键点 (Linux)的提权是怎么一回事:  收集 – 枚举,枚举和一些更多的枚举. ...

  7. .NET Fframework

    .NET框架示意图: 该框架是微软推出的完全面向对象的软件开发与运行平台.其有两个主要 组将:CLR:公共语言运行库(Common Language Runtime,简称CLR)和.NET Frame ...

  8. DESede对称加密算法工具类

    利用Cipher的核心功能,自己封装了一个加密解密的工具类,可以直接使用.在使用之前需要先下载commons-codec-1.9.jar,并导入项目. 工具类如下: package com.pcict ...

  9. 云计算之路-试用Azure:一次失败的SQL Server向SQL Azure的迁移尝试

    如果数据库用的是SQL Server,那SQL Azure无疑是最吸引人的地方之一.在测试了虚拟机磁盘IO之后,我们迫不急待地进行了SQL Azure的测试. (一) 首先进入manage.windo ...

  10. Asp.Net 之 二维码生成

    首先,引用 ThoughtWorks.QRCode.dll . 简单二维码生成及解码代码: //生成二维码方法一 private void CreateCode_Simple(string nr) { ...