回复 10楼 诸葛修勤
初始化一个 Thread数组,有10个数组元素。数组类型是Thread类。。。没有初始化的数组是不能用的。
Thread[] threads = new Thread[10]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(new Ticket(i + 1)); threads[i].start(); }那么 for 里面的? new Thread()
public class main { public static void main(String args[]) { yxf y = new yxf(); y.td_1.start(); } } class yxf implements Runnable { Thread td_1, td_2; int i = 1; int sum = 0; yxf () { td_1 = new Thread(this); td_2 = new Thread(this); } @Override public void run() { // TODO Auto-generated method stub while ( i<=10 ) { sum += i; System.out.println(sum); ++i; if (6 == i && Thread.currentThread() == td_1) { System.out.println("over thread td_1"); td_2.start(); } } } }