本专栏多线程目录:
(十一)sleep(1)、sleep(0)和sleep(1000)的区别
(十二)yield、notify、notifyAll、sleep、join、wait的区别
Callable和Runnable都是一个接口。
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只有一个run方法,在使用普通线程的时候,我们可以实现Runnable接口即可,Thread类在调用start()函数后就是执行的是Runnable的run()函数。
简单使用:
Thread thread =new Thread(new TestRunnable());
thread.start();
Runnable的run方法没有返回值。
demo:
public class ThreadPoolALL {
public static void main(String[] args) {
new ThreadPoolALL().ExecutorThreadPool();
}