问一下,这里怎么会有两个线程》?
public class ThreadJoinTest
{
public static void main(String args[]) throws Excetion
{
int i=0;
Hello h=new Hello();
Thread t=new Thread(h);
t.setPriority(Thread.MAX_PRIORITY);
t.start();
System.out.println("Please stop saying Hello and say good morning!");
h.stopRunning();
while(i<5)
{
System.out.println("Good Morning"+i++);
}
}
}
class Hello implements Runnable
{
int i=0;
private boolean timeToQuit=false;
public void run()
{
while(!timeToQuit)
{
System.out.println("Hello"+i++);
try {
if(i%2==0)
Thread.sleep(10);
}catch(Exception e){}
public void stopRunning()
{
timeToQuit=true;
}
}
}
结果如下:
Hello0
Hello1
Hello2
Hello3
Please stop saying Hello and say good morning
Good Morning0
Good Morning1
Good Morning2
Good Morning3
Good Morning4
我看不出这个程序有两个线程,可是书上说用两个。能否帮我找一下答案?