简体   繁体   English

如何停止程序直到满足某个条件?

[英]How to stop the program until a certain condition is met?

a question:一个问题:

the main program is executed in the main thread.主程序在主线程中执行。 An object of class Timer (swing) generates an event every 30 seconds. class Timer (swing) 的 object 每 30 秒生成一个事件。

As a result of this, the handler of this event is launched (in a parallel thread).因此,该事件的处理程序被启动(在并行线程中)。

I need to stop the main thread from executing while the event handler will execute.我需要在事件处理程序执行时停止执行主线程。

Those.那些。 as soon as the timer handler starts executing, the main program should stop (it has a pause).一旦定时器处理程序开始执行,主程序应该停止(它有一个暂停)。

And as soon as the timer handler completes its work, the main program should continue its work.并且一旦定时器处理程序完成它的工作,主程序应该继续它的工作。

Tell me, with what help is it more convenient and more correct to solve this problem?告诉我,解决这个问题有什么帮助更方便更正确?

You can block your Mainthread by calling: wait() then after your other thread finished you can call notify() to continue the mainthread.您可以通过调用来阻塞主线程: wait()然后在其他线程完成后,您可以调用notify()以继续主线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM