前文铺垫
面向的读者是已经熟练使用过线程池,集成Runnable,直接new Thread 里面编写run方法
虽然方式和种类很多,但是运行到源码层面方式其实只有一种,我们此篇文章就进行讲解
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 只是一个接口,所以一个类实现了Runnable,直接调用这个类的run方法和调用一个普通 的方法没什么区别,并不会启动一个线程