回复 10楼 诸葛修勤
初始化一个 Thread数组,有10个数组元素。数组类型是Thread类。。。没有初始化的数组是不能用的。
2011-04-17 14:03
程序代码: 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()
2011-04-17 14:07
Thread[] threads = new Thread[10];Thread threads[10];
2011-04-17 14:09
程序代码: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();
}
}
}
}
2011-04-17 14:12
2011-04-17 14:15
2011-04-18 14:53
2011-04-18 14:58

2011-04-18 15:21
慢慢来了只能
2011-04-18 16:08
2011-04-18 16:11