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

------------------------------------------------------------------------------------------------分割线---------------------------------------------------------------------------------------------------------------------------------------------------------------------------