stop();因为这样连主线程都退出去了???那下面这个程序呢??class Test { public static void main(String args[]) { A a = new A(); B b = new B(); a.start(); b.start(); } }class A extends Thread { public void run() { while(true) { try { this.sleep(100); } catch (Exception ex) { }
System.out.println ("A"); } } }class B extends Thread { public void run() { int i =0; while(i<100) { try { this.sleep(100); } catch(Exception e) {
如果这样做的话,将来run()是否永远都不会运行了,还是说每次都运行,但以判断条件不对又退出了反复这样。
除此之外,没有别的办法吗,例如unix下的kill什么的?
{
public static void main(String args[])
{
A a = new A();
B b = new B();
a.start();
b.start();
}
}class A extends Thread
{
public void run()
{
while(true)
{
try
{
this.sleep(100);
}
catch (Exception ex) {
}
System.out.println ("A");
}
}
}class B extends Thread
{
public void run()
{
int i =0;
while(i<100)
{
try
{
this.sleep(100);
}
catch(Exception e)
{
}
System.out.println (i);
i++;
if(i==10)
{
this.stop();
}
}
}
}