Suspend test execution until application becomes idle

后端 未结 2 990
感情败类
感情败类 2021-01-27 00:28

Is it feasible to implement some util method to suspend test (current thread) execution until application becomes idle?
Idle means:
1. there were no GUI events added to

2条回答
  •  有刺的猬
    2021-01-27 01:03

    You can use Toolkit.getDefaultToolkit().addAWTEventListener(listener, eventMask) to subscribe to AWT event queue, so you can detect whether events are not added for some period of time.

    I think that you need your custom code to monitor working threads, i.e. something in the beginning and end of run() method.

    The problem is to "suspend the test execution". If your test is running in thread theoretically you can invoke the thread's suspend() method. But it is deprecated and should not be used. To perform clear implementation you should make your custom code that asks status during execution of the thread and calls wait() once it detects that the test must be suspended. When your code that monitors AWT event queue and working threads decides that test may be resumed it should call appropriate notify().

    Probably better solution from design point of view is Actors model. There are several java framework that provide this functionality.

提交回复
热议问题