0

I need to constantly check the embedded database against constantly changing values.

public void runInBG() { //this method called in a seperate thread
    while(true) {
     while(els.hasElements()) {//els values change constantly
      Test el = (Test)els.next();
       String sql = "SELECT * FROM Test WHERE id = '" + el.getId() + "'";
       Record r = db.getTestRecord(sql);//this function makes connection, executeQuery etc...and return Record object with values
       if(r != null) {
         //do something
        }
      }
    }
}

I cannot use a timer since I need this to be running constantly and anytime a change occurs it must react instantaneously.

The problem that I'm having is that opening and closing the connection takes too long for each iteration which is why I'm now looking into a persistent connection.

The database does not change constantly but still needs to be monitored constantly relative to the changing values.

Any advice would be appreciated.

Olaf
  • 6,249
  • 1
  • 19
  • 37
  • 3
    Can't you use a trigger in the database instead of check constantly? – Evans May 14 '13 at 17:05
  • Can you explain a bit more regarding the trigger? I'm not familar with it. Thanks –  May 14 '13 at 17:07
  • Yes Luiggi, it is the same question framed a bit differently though and with the exclusion of timers. –  May 14 '13 at 17:12
  • 2
    Basically it´s a stored code executed when some event happens. Can be programmed to be fired when a table suffer a change (and be fired before the change takes effect or after the change). The implementation depends on the database product you are using, better search in the documentation – Evans May 14 '13 at 17:12
  • 1
    What type of database? – npgall May 14 '13 at 17:20
  • h2 database (embedded) –  May 14 '13 at 17:20

0 Answers0