/*
* 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並將自身做爲參數傳遞進去的方式被實例化.java
在大多數狀況下,Runnable接口應當用在你只計劃重寫run方法,並不許備使用其餘Thread的方法時程序員
(由於Runnable只是一個接口,只有一個抽象的run(),Thread是實現類,有更多其餘的方法可被調用)less
* 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方法的通俗約定是能夠作任何行爲.ide
* @see java.lang.Thread#run() */ public abstract void run();}