如何暂停某些线程的执行.我有线程t,我有两个按钮,暂停和继续.暂停时,我需要暂停线程执行,然后继续从之前停止的位置开始线程开始执行.在听众中放什么?
How to pause execution of some Thread. I have Thread t and I have two buttons, PAUSE and CONTINUE. On pause I need to pause thread execution and on continue to thread start execution from point where stoped before. What to put in listeners?
Java中的线程是协作的,这意味着您不能强制线程停止或暂停,而是向线程发送所需的信息和线程(=逻辑)本身完成.
Threading in Java is cooperative, which means you can not force the thread to stop or pause, instead you signal to the thread what you want and thread (= your logic) does it itself.
为此使用同步,wait()和notify().
Use synchronized, wait() and notify() for that.
synchronized
块内. wait()
. commonObject.notify()
.这篇关于如何暂停线程执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!