总体概览一下,写的很好:https://blog.csdn.net/u011163372/article/details/73995897
1、继承Thread类创建线程
package com.thre;
public class TestThread {
public static void main(String[] args) {
ThreadA a1 = new ThreadA();
ThreadA a2 = new ThreadA();
a1.start();
a2.start();
}
}
class ThreadA extends Thread{
@Override
public void run() {
System.out.println("run...");
}
}
2、实现Runnable接口创建线程
package com.thre;
public class TestThread {
public static void main(String[] args) {
Thread a1 = new Thread(new RunA());
Thread a2 = new Thread(new RunA());
a1.start();
a2.start();
}
}
class RunA implements Runnable{
@Override
public void run() {
System.out.println("run...");
}
}
3、使用Executors、Callable、Future实现有返回结果的线程,
可返回值的任务必须实现Callable接口。无返回值的任务必须实现Runnable接口。
https://blog.csdn.net/the_fool_/article/details/79869046