Java中创建多线程的三种方法
1、继承Thread类创建线程
2、实现Runnable接口创建线程
3、使用Callable和Future创建线程
------------------------------------------------------------------------------------------------分割线---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
一、继承Thread类创建线程
/** * @ Author :ZhuZhu * @ Date :Created in 16:54 2019/6/9 * @ Description: */ public class MyThread extends Thread { // 重写run方法 public void run(){ for (int i = 1;i <= 5;i++){ System.out.println("Thread :"+i); } } }
public class Test1 {
public static void main(String[] args) throws InterruptedException {
MyThread thread = new MyThread();
thread.start();
}
}
打印结果:
------------------------------------------------------------------------------------------------分割线---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
原文:https://www.cnblogs.com/ldh666/p/10994042.html