不明白为什么打出来的是
Thread-0-----50321
Thread-0-----50322
Thread-0-----50323
Thread-0-----50324
Thread-0-----50325
Thread-0-----50326
Thread-0-----50327public class TreadDemo4 {
public static void main(String [] args)
{
SellTickets tt=new SellTickets();
Thread t=new Thread(tt);
t.start();
while(true)
{
int i=0;
if (i==100)
{
try {
t.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("main Thread is running"+i++);
}
}
}
}
class SellTickets implements Runnable
{
public void run()
{ int i=0;
while(true)
{
System.out.println(Thread.currentThread().getName()+"-----"+i++);
}
}
}
Thread-0-----50321
Thread-0-----50322
Thread-0-----50323
Thread-0-----50324
Thread-0-----50325
Thread-0-----50326
Thread-0-----50327public class TreadDemo4 {
public static void main(String [] args)
{
SellTickets tt=new SellTickets();
Thread t=new Thread(tt);
t.start();
while(true)
{
int i=0;
if (i==100)
{
try {
t.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("main Thread is running"+i++);
}
}
}
}
class SellTickets implements Runnable
{
public void run()
{ int i=0;
while(true)
{
System.out.println(Thread.currentThread().getName()+"-----"+i++);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货