views:

71

answers:

1

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.

A: 

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.

aioobe
To explain: The test sends a message (e.g. txt file) to the application and then checks processing and if data has been added to the database. The processing time depends on the message and therfore I regurarly check the table for a specified max. time (-> iterationsteps). If there are no data in the table after the specifed time, the test will fail, otherwise going on.The monitor itself checks another table and it has to warn or even stop test, if this table get a new entry.
lasombra