Skip to content

Runnable

About 183 wordsLess than 1 minute

2025-06-02

今天在学习多线程的时候看到了Runnable这个接口,简单了解一下。

Runnable接口只有一个抽象方法,就是run方法。

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

在后面看到的Thread类是实现了Runnable接口。

Thread和Runnable有什么区别呢?

  • Thread是类,Runnable是接口,如果一个类已经继承了某个类,想要实现线程功能只能实现Runnable接口
  • Thread多表示线程,Runnable多表示为任务。

Changelog

6/3/25, 1:49 AM
View All Changelog
  • d3a6d-Merge branch 'dev1'on

求求了,快滚去学习!!!

求求了求求了,快去学习吧!

【题单】贪心算法

不知道方向的时候,可以多看看书,书会给你指明下一步该干什么,加油!