标签:getname com print create span 方法 练习 get override
1 package com.yhqtv.exer; 2 /* 3 * 练习:创建两个分线程,其中一个线程遍历100以内的偶尔,另一个线程遍历100以内的奇数 4 * 5 * @author XMKJ yhqtv.com Email:yhqtv@qq.com 6 * @create 2020-04-28-11:26 7 * */ 8 9 public class ThreadDemo { 10 public static void main(String[] args) { 11 // MyThread1 m1=new MyThread1(); 12 // MyThread2 m2=new MyThread2(); 13 // m1.start(); 14 // m2.start(); 15 16 //创建Thread类的匿名子类的方法 17 new Thread(){ 18 @Override 19 public void run() { 20 for (int i = 0; i < 100; i++) { 21 if(i%2==0){ 22 System.out.println(Thread.currentThread().getName()+"--"+i); 23 } 24 25 } 26 } 27 }.start(); 28 29 new Thread(){ 30 @Override 31 public void run() { 32 for (int i = 0; i < 100; i++) { 33 if(i%2==1){ 34 System.out.println(Thread.currentThread().getName()+"--"+i); 35 } 36 } 37 } 38 }.start(); 39 } 40 } 41 class MyThread1 extends Thread{ 42 @Override 43 public void run() { 44 for (int i = 0; i < 100; i++) { 45 if(i%2==0){ 46 System.out.println(Thread.currentThread().getName()+"--"+i); 47 } 48 49 } 50 } 51 } 52 class MyThread2 extends Thread{ 53 @Override 54 public void run() { 55 for (int i = 0; i < 100; i++) { 56 if(i%2==1){ 57 System.out.println(Thread.currentThread().getName()+"--"+i); 58 } 59 } 60 } 61 }
标签:getname com print create span 方法 练习 get override
原文地址:https://www.cnblogs.com/yhqtv-com/p/12793149.html