oThreadPool = new WorkerThreadPool(oCsr, oEnvProps);
// Register callbacks on each worker thread
ListIterator oIter = oCallbacks.listIterator();
while (oIter.hasNext())
oThreadPool.registerCallback((WorkerThreadCallback) oIter.next());
dtStartDate = new Date();
do {
try {
while (bContinue) {
oJcn = oDbb.getConnection("SchedulerDaemon");
oJcn.setAutoCommit(true);
// Count how many atoms are pending of processing at the database
oStmt = oJcn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
// ***************************************************
// Finish all the jobs that have no more pending atoms
sSQL = "SELECT j.gu_job FROM k_jobs j WHERE ("+
"j.id_status="+String.valueOf(Job.STATUS_PENDING)+" OR "+
"j.id_status="+String.valueOf(Job.STATUS_RUNNING)+") AND "+
"NOT EXISTS (SELECT a.pg_atom FROM k_job_atoms a WHERE "+
"j.gu_job=a.gu_job AND a.id_status IN ("+
String.valueOf(Atom.STATUS_PENDING)+","+
String.valueOf(Atom.STATUS_RUNNING)+","+
String.valueOf(Atom.STATUS_SUSPENDED)+"))";
if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery("+sSQL+") on connection with process id. "+oJcn.pid());
oRSet = oStmt.executeQuery(sSQL);
LinkedList<String> oFinished = new LinkedList<String>();
while (oRSet.next()) {
oFinished.add(oRSet.getString(1));
} // wend
oRSet.close();
oStmt.close();
if (DebugFile.trace) DebugFile.writeln("Already finished jobs "+String.valueOf(oFinished.size()));
if (oFinished.size()>0) {
sSQL = "UPDATE k_jobs SET id_status="+String.valueOf(Job.STATUS_FINISHED)+",dt_finished="+DBBind.Functions.GETDATE+" WHERE gu_job=?";
if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement("+sSQL+") on connection with process id. "+oJcn.pid());
PreparedStatement oUpdt = oJcn.prepareStatement(sSQL);
oIter = oFinished.listIterator();
while (oIter.hasNext()) {
oUpdt.setObject(1, oIter.next(), java.sql.Types.CHAR);
oUpdt.executeUpdate();
} // wend
oUpdt.close();
} // fi