@Override
public void run()
{
+ long lastQuery = System.currentTimeMillis();
while (true)
{
PreparedStatement q = null;
try
{
- this.queryLock.wait();
+ this.queryLock.wait(60 * 1000L);
}
catch (InterruptedException e) { }
}
try
{
q.executeUpdate();
+ lastQuery = System.currentTimeMillis();
log.log(Level.FINE, "Successfully executed " + q + " in worker thread");
}
this.close(q, null);
}
+
+ if (System.currentTimeMillis() - lastQuery > 60 * 1000)
+ {
+ lastQuery = System.currentTimeMillis();
+
+ try (PreparedStatement stmt = this.con.prepareStatement("SELECT 1"))
+ {
+ stmt.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
}
}
public static SQL getConnection(final String name)
{
- SQL sql = null;
-
try
{
for (Database d : Acidictive.conf.database)
if (!d.name.equals(name))
continue;
- return sql = new SQL(d.host, d.user, d.pass);
+ return new SQL(d.host, d.user, d.pass);
}
}
catch (ClassNotFoundException ex)
throw new RuntimeException(e.getMessage());
}
- return sql;
+ return null;
}
}