有关多线程的问题
判断已知数是否为质数 + 显示时间 ,要求判断完毕同时停止时间输出但未能如愿 ,望高手指点 , 小弟感激不敬~~~~~~~~~~~~~~
import java.util.*;
class TestThread208_4
{
public static void main(String[] args)
{
ShowTime time = new ShowTime();
DoCount count = new DoCount();
Thread thread1 = new Thread(time);
Thread thread2 = new Thread(count);
thread1.start();
thread2.start();
}
}
class ShowTime implements Runnable
{
boolean flg = true;
public void run()
{
while(flg)
{
System.out.println(new Date());
try{
Thread.sleep(600);
}catch(InterruptedException e){
System.err.println(e);
}
}
}
public void stopRun()
{
flg = false;
}
}
class DoCount implements Runnable
{
public void run()
{
int num = 34243;
int j = 0;
for(int i=2;i<num;i++)
{
if(num%i==0) j=1;
else j=2;
}
switch(j)
{
case 1:
System.out.println(num+"不是质数");
break;
case 2:
System.out.println(num+"是质数");
break;
}
new ShowTime().stopRun();[size=2]
}
}[/size]