开发者

Jsystem: Thread.sleep() in testcase pauses Monitor

开发者 https://www.devze.com 2022-12-28 18:10 出处:网络
I guess I miss some 开发者_如何学编程basical stuff, regadring threads. However, here my problem:

I guess I miss some 开发者_如何学编程basical stuff, regadring threads. However, here my problem:

I have a monitor running. On the other hand I have a test. The test does execute a sql query several times, between each execution waiting some ms with Thread.sleep(xy).

for (int i = 0; (i < iterationsteps); i++) { 
    rs = myQuery.execute(); 
    //check if rs is empty 
    if (!rs.next()) { Thread.sleep(1000); 
    } 
}

Now the problem is that due to this Thread.sleep(1000) also the Monitor seems to sleep (at least it does not check). I thought a monitor is a seperate thread.


I'm not sure what your aiming at with your code, but one thing is for sure myQuery.execute() will block until it is finished.

If you want to do it in the background, you would have to spawn a separate thread for it:

    new Thread() {
        public void run() {
            rs = myQuery.execute(); 
        }
    }.start();

However, this has many implications. Some are obvious, some are not, and it would definitely require some synchronization code.

Unless you know what you're doing, I would strongly encourage you to go with a single-threaded approach.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号