方法一:多线程实现

package com.heima.Thread;

public class Demo1_Thread {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
     Mythread mt = new Mythread();        // 创建Thread类的子类对象
     mt.start();
     for(int i=0;i<1000;i++) {
    	 System.out.println("bb");
     }
	} 

}


class Mythread extends Thread {          // 继承Thread
	
	public void run() {                 // 重写run方法
		for(int i=0 ;i < 1000; i++) {    // 将要执行的代码写到run方法中
			System.out.println("aaaaaaaaaaaaaaaa");
		}
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_42371928/article/details/89056761