private void addMaintenanceTimer(int idAset, int siklus, MaintenanceCycleTimeUnit timeUnit) { MaintenanceTask mt = new MaintenanceTask(); mt.setAssetId(idAset); mt.setCycleTime(siklus); mt.setTimeUnit(timeUnit); if (maintenanceTimer.containsKey(mt.getAssetId())) { maintenanceTimer.get(idAset).cancel(); maintenanceTimer.get(idAset).purge(); } Timer timer = new Timer(); maintenanceTimer.put(mt.getAssetId(), timer); timer.schedule(mt, 0, mt.getTimeUnit().toMillis(mt.getCycleTime())); }
private void initMaintenanceScheduler() throws SQLException { String query = "SELECT * FROM " + MAINTENANCE_TABLE; ResultSet rs = executeQuery(query); while (rs.next()) { MaintenanceTask mt = new MaintenanceTask(); mt.setAssetId(rs.getInt("id_aset")); mt.setCycleTime(rs.getInt("siklus")); MaintenanceCycleTimeUnit cycleTimeUnit = MaintenanceCycleTimeUnit.getInstance(rs.getString("satuan_waktu_siklus")); mt.setTimeUnit(cycleTimeUnit); Timer timer = new Timer(); maintenanceTimer.put(mt.getAssetId(), timer); timer.schedule(mt, 0, mt.getTimeUnit().toMillis(mt.getCycleTime())); } }