public class Test extends Thread { private int startingNumber = 0; // 设置开始计数值 public Test(int startingNumber) { this.startingNumber = startingNumber; } public void run() { // 循环50次 for (int i = startingNumber; i < (startingNumber + 50); i++) { System.out.println(i); try { sleep((long) (Math.random() * 600)); // 睡眠时间随机 } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void main(String args[]) throws Exception { Test t1 = new Test(1000), t2 = new Test(2000), t3 = new Test(3000); t1.start(); t2.start(); t3.start(); } }