Heim  >  Artikel  >  Java  >  Vergleich von Runnable und Callable in Java

Vergleich von Runnable und Callable in Java

PHPz
PHPznach vorne
2023-04-21 21:58:151377Durchsuche

1 Der Kern ist die run()-Methode, die keinen Rückgabewert hat, aber die run()-Methode kann nicht auf Executoren angewendet werden 3. Instanzen

Schnittstellendefinition von Runnable und Callable

@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();
}
@FunctionalInterface
public interface Callable<V> {
    /**
     * Computes a result, or throws an exception if unable to do so.
     *
     * @return computed result
     * @throws Exception if unable to compute a result
     */
    V call() throws Exception;
}

Das obige ist der detaillierte Inhalt vonVergleich von Runnable und Callable in Java. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:yisu.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen