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.