Runnable接口的源码阅读

/*
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*/

package java.lang;

/**
* The <code>Runnable</code> interface should be implemented by any
* class whose instances are intended to be executed by a thread. The
* class must define a method of no arguments called <code>run</code>.
* <p>
任意希望其实例通过线程执行的类都需要实现Runnable接口.这些类必须定义一个无参数的run方法
* This interface is designed to provide a common protocol for objects that
* wish to execute code while they are active. For example,
* <code>Runnable</code> is implemented by class <code>Thread</code>.
* Being active simply means that a thread has been started and has not
* yet been stopped.
此接口旨在为希望在存活时执行代码的对象提供公共接口.
例如,Runnable被Thread类所实现.存活仅仅意味着线程已经启动了并且还没有被终止.
* <p>
* In addition, <code>Runnable</code> provides the means for a class to be
* active while not subclassing <code>Thread</code>. A class that implements
* <code>Runnable</code> can run without subclassing <code>Thread</code>
* by instantiating a <code>Thread</code> instance and passing itself in
* as the target. In most cases, the <code>Runnable</code> interface should
* be used if you are only planning to override the <code>run()</code>
* method and no other <code>Thread</code> methods.

  此外,Runnable为不继承Thread的类提供了可用的方法。
  一个实现了Runnable接口的类可以无需成为Thread的子类而是创建一个Thread并将自身作为参数传递进去的方式被实例化.

  在大多数情况下,Runnable接口应当用在你只计划重写run方法,并不准备使用其他Thread的方法时

  (因为Runnable只是一个接口,只有一个抽象的run(),Thread是实现类,有更多其他的方法可被调用)


* This is important because classes should not be subclassed
* unless the programmer intends on modifying or enhancing the fundamental
* behavior of the class.
*
这很重要,因为类不应该被子类化除非程序员打算修改或增强基础类的行为.
* @author Arthur van Hoff
* @see java.lang.Thread
* @see java.util.concurrent.Callable
* @since JDK1.0
*/
@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.
 当一个对象实现了Runnable接口用于创建线程、启动线程导致对象的run方法在单独执行的线程中被调用
* <p>
* The general contract of the method <code>run</code> is that it may
* take any action whatsoever.
*


  run方法的通俗约定是可以做任何行为.


* @see java.lang.Thread#run()
*/
public abstract void run();
}
原文地址:https://www.cnblogs.com/akanga/p/11216598.html