Buggy code:
public class CheckSchedulerJob extends Thread { Logger log = Logger . getLogger ( CheckSchedulerJob . class ) ; Logger netlogger = Logger . getLogger ( "netlogger" ) ; long DEFAULT_SLEEP_TIME = 20000 ; public CheckSchedulerJob ( String name ) { } public void run ( ) { } public synchronized void execute ( ) { NetLogger netLog = NetLogger . getTlogger ( ) ; netlogger . info ( netLog . start ( "maddash.CheckSchedulerJob.execute" ) ) ; int schedJobCount = 0 ; int totalJobCount = 0 ; Connection conn = null ; try { System . gc ( ) ; MaDDashGlobals globals = MaDDashGlobals . getInstance ( ) ; conn = globals . getDataSource ( ) . getConnection ( ) ; long time = ( System . currentTimeMillis ( ) ) // 1000 ; netlogger . debug ( netLog . start ( "maddash.CheckSchedulerJob.execute.queryDb" ) ) ; <START_BUG> PreparedStatement selStmt = conn . prepareStatement ( ( "SELECT<seq2seq4repair_space>c.id,<seq2seq4repair_space>c.gridName,<seq2seq4repair_space>" + ( ( ( "c.rowName,<seq2seq4repair_space>c.colName,<seq2seq4repair_space>t.checkType,<seq2seq4repair_space>t.checkParams,<seq2seq4repair_space>t.checkInterval,<seq2seq4repair_space>" + "t.retryInterval,<seq2seq4repair_space>t.retryAttempts,<seq2seq4repair_space>t.timeout,<seq2seq4repair_space>c.statusMessage<seq2seq4repair_space>FROM<seq2seq4repair_space>checkTemplates<seq2seq4repair_space>AS<seq2seq4repair_space>t,<seq2seq4repair_space>" ) + "checks<seq2seq4repair_space>AS<seq2seq4repair_space>c<seq2seq4repair_space>WHERE<seq2seq4repair_space>c.active<seq2seq4repair_space>=<seq2seq4repair_space>1<seq2seq4repair_space>AND<seq2seq4repair_space>t.id<seq2seq4repair_space>=<seq2seq4repair_space>c.checkTemplateId<seq2seq4repair_space>AND<seq2seq4repair_space>" ) + "c.nextCheckTime<seq2seq4repair_space><=<seq2seq4repair_space>?<seq2seq4repair_space>AND<seq2seq4repair_space>c.status<seq2seq4repair_space>!=<seq2seq4repair_space>?<seq2seq4repair_space>ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>c.nextCheckTime<seq2seq4repair_space>ASC" ) ) ) ; <END_BUG> selStmt . setLong ( 1 , time ) ; selStmt . setInt ( 2 , RESULT_MAINTENANCE ) ; selStmt . setMaxRows ( globals . getJobBatchSize ( ) ) ; ResultSet checksToRun = selStmt . executeQuery ( ) ; netlogger . debug ( netLog . end ( "maddash.CheckSchedulerJob.execute.queryDb" ) ) ; while ( checksToRun . next ( ) ) { totalJobCount ++ ; if ( globals . isCheckScheduled ( checksToRun . getInt ( 1 ) ) ) { continue ; } String jobKey = UUID . randomUUID ( ) . toString ( ) ; String triggerName = "runCheckTrigger-" + jobKey ; String jobName = "runCheckJob-" + jobKey ; SimpleTrigger trigger = new SimpleTrigger ( triggerName , null , new Date ( ) , null , 0 , 0L ) ; JobDetail jobDetail = new JobDetail ( jobName , "RUN_CHECKS" , RunCheckJob . class ) ; JobDataMap dataMap = new JobDataMap ( ) ; dataMap . put ( "checkId" , checksToRun . getInt ( 1 ) ) ; dataMap . put ( "gridName" , checksToRun . getString ( 2 ) ) ; dataMap . put ( "rowName" , checksToRun . getString ( 3 ) ) ; dataMap . put ( "colName" , checksToRun . getString ( 4 ) ) ; dataMap . put ( "checkType" , globals . getCheckTypeClassMap ( ) . get ( checksToRun . getString ( 5 ) ) ) ; dataMap . put ( "checkParams" , checksToRun . getString ( 6 ) ) ; dataMap . put ( "checkInterval" , checksToRun . getInt ( 7 ) ) ; dataMap . put ( "retryInterval" , checksToRun . getInt ( 8 ) ) ; dataMap . put ( "retryAttempts" , checksToRun . getInt ( 9 ) ) ; dataMap . put ( "timeout" , checksToRun . getInt ( 10 ) ) ; dataMap . put ( "statusMessage" , checksToRun . getString ( 11 ) ) ; dataMap . put ( "rowVars" , DimensionUtil . getParams ( checksToRun . getString ( 3 ) , conn ) ) ; dataMap . put ( "colVars" , DimensionUtil . getParams ( checksToRun . getString ( 4 ) , conn ) ) ; jobDetail . setJobDataMap ( dataMap ) ; globals . updateScheduledChecks ( checksToRun . getInt ( 1 ) , true ) ; globals . getScheduler ( ) . scheduleJob ( jobDetail , trigger ) ; schedJobCount ++ ; } conn . close ( ) ; netlogger . info ( netLog . end ( "maddash.CheckSchedulerJob.execute" ) ) ; log . debug ( ( ( ( ( "Scheduled<seq2seq4repair_space>" + schedJobCount ) + "//" ) + totalJobCount ) + "<seq2seq4repair_space>new<seq2seq4repair_space>jobs" ) ) ; } catch ( Exception e ) { if ( conn != null ) { try { conn . close ( ) ; } catch ( SQLException e2 ) { } } netlogger . info ( netLog . error ( "maddash.CheckSchedulerJob.execute" , e . getMessage ( ) ) ) ; log . error ( ( "Error<seq2seq4repair_space>scheduling<seq2seq4repair_space>job<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; e . printStackTrace ( ) ; throw new RuntimeException ( e . getMessage ( ) ) ; } } }

Fix:
PreparedStatement selStmt = conn . prepareStatement ( ( "SELECT<seq2seq4repair_space>c.id,<seq2seq4repair_space>c.gridName,<seq2seq4repair_space>" + ( ( ( "c.rowName,<seq2seq4repair_space>c.colName,<seq2seq4repair_space>t.checkType,<seq2seq4repair_space>t.checkParams,<seq2seq4repair_space>t.checkInterval,<seq2seq4repair_space>" + "t.retryInterval,<seq2seq4repair_space>t.retryAttempts,<seq2seq4repair_space>t.timeout,<seq2seq4repair_space>c.statusMessage<seq2seq4repair_space>FROM<seq2seq4repair_space>checkTemplates<seq2seq4repair_space>AS<seq2seq4repair_space>t,<seq2seq4repair_space>" ) + "checks<seq2seq4repair_space>AS<seq2seq4repair_space>c<seq2seq4repair_space>WHERE<seq2seq4repair_space>c.active<seq2seq4repair_space>=<seq2seq4repair_space>1<seq2seq4repair_space>AND<seq2seq4repair_space>t.id<seq2seq4repair_space>=<seq2seq4repair_space>c.checkTemplateId<seq2seq4repair_space>AND<seq2seq4repair_space>" ) + "c.nextCheckTime<seq2seq4repair_space><=<seq2seq4repair_space>?<seq2seq4repair_space>AND<seq2seq4repair_space>c.checkStatus<seq2seq4repair_space>!=<seq2seq4repair_space>?<seq2seq4repair_space>ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>c.nextCheckTime<seq2seq4repair_space>ASC" ) ) ) ;