Java“一劳永逸”线
我有一个方法
public static void startAnimation() {
new AnimationThread().run();
}
,其中 AnimationThread 实现了 runnable ,其构造函数是:
public AnimationThread() {
new Thread(this, "Animation Thread");
EventQueue.setAnimationCounter(0);
alive = true;
}
我从小程序的 init() 方法调用的方法挂起,因为它从不返回值。有没有办法启动这个线程并完成 init() 方法,以便我的小程序启动!
谢谢
I have a method
public static void startAnimation() {
new AnimationThread().run();
}
where AnimationThread implements runnable and its constructor is:
public AnimationThread() {
new Thread(this, "Animation Thread");
EventQueue.setAnimationCounter(0);
alive = true;
}
which i am calling from the init() method of an applet hangs as it never returns a value. Is there a way to start this thread and get the init() method to finish so that my applet will start!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要稍微移动一下:
start()
是神奇的Thread
方法,它在不同的线程上运行代码;AnimationThread
构造函数调用后会正常返回,AnimationThread.run()
将在新线程中执行。You need to move things around a bit:
start()
is the magicThread
method that runs code on a different thread; theAnimationThread
constructor will return normally after calling it, theAnimationThread.run()
will execute in a new thread.也许您应该调用
start
方法而不是run
方法。只有start
方法真正执行了一个新线程。Maybe you should call the
start
method instead therun
method. Onlystart
method really executes a new thread.