标签:style blog color ar java for sp div art
1.定义一个Thread的子类
2.重写run方法
3.在需要的定法创建子类对象
4.调用子类对象的start方法(不要调用run方法,调用run就变成单线程了)
1 public class Main { 2 public static void main(String[] args) { 3 SubThread st = new SubThread(); 4 st.start(); // 启动子线程,调用相应的run方法 5 6 for (int i = 1; i < 100; i++) { 7 System.out.println(Thread.currentThread().getName() + ":" + i); 8 } 9 } 10 11 12 } 13 14 // 1.继承thread类 15 // 2.重写run 16 class SubThread extends Thread { 17 public void run() { 18 for (int i = 1; i<= 100; i++) { 19 System.out.println(i); 20 } 21 } 22 }
标签:style blog color ar java for sp div art
原文地址:http://www.cnblogs.com/baisu/p/4034396.html