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.
精彩评论