實現執行緒類的兩種方式
阿新 • • 發佈:2019-09-22
一、讓目標類繼承Thread類
package com.atzhongruan.springboot_boostrap.Test; /** * @Author jose * date 2019 */ public class Task1 extends Thread{ @Override public void run() { for (int j = 0; j < 100000; j++) { System.out.println("i============================="+j); } } }
package com.atzhongruan.springboot_boostrap.Test; /** * @Author jose * date 2019 */ public class Task2 extends Thread { @Override public void run() { for (int i = 0; i < 1000000; i++) { System.out.println("i="+i); } } }
package com.atzhongruan.springboot_boostrap.Test; /** * @Author jose * date 2019 */ public class Window { public static void main(String[] args) { //建立執行緒1 Task1 task1 = new Task1(); //建立執行緒2 Task2 task2 = new Task2(); //執行程式 task1.start(); task2.s