它可以在它死后重新开始吗? [英] Can I start a thread again after it has died?
本文介绍了它可以在它死后重新开始吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在Thread对象上使用start()并且run()方法返回,是否可以再次调用start()?
If I use start() on a Thread object and the run() method returns, is it possible to call start() again?
例如,
MyThread myThread = new MyThread();
myThread.start();
// run method executes and returns in 2 seconds
// sleep for 5 seconds to make sure the thread has died
myThread.start();
我只是想知道因为我的代码正在抛出IllegalThreadStateExceptions,所以想知道是不是因为你可以不要做以上。
I'm just wondering because my code is throwing IllegalThreadStateExceptions, so want to know if it's because you can't do the above.
推荐答案
不,你不能。和 <$的Javadoc c $ c> Thread.start() 方法告诉你!
No, you can't. And the Javadoc for the Thread.start()
method tells you that!
这篇关于它可以在它死后重新开始吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文