线程调用问题
设一个类A,A中有一个方法output(),然后一个类B继承A,当B运行时,每隔3秒就运行一次A中的output()方法,要用线程技术来设置!
class A implements Runnable
{
public void run()
{
new A().output();
}
public synchronized void output()
{
System.out.println("123456789");
}
};
public class B1 extends A
{
public static void main(String[] args)
{
while(true)
{
try{Thread.sleep(3000);}
catch(Exception e){}
Thread t = new Thread(new A());
t.start();
//t.start();
//t.start();
}
}
}
这种程序设计应怎么样设置更更好呢,我写了个但不够理想吧,大家看下有什么不好之处请指点,还有一个问题就是若我t.start()----后面两个没注释掉,将会出现Thread的错误,怎么修改才可以运行呢!