J'ai créé un processus batch complet et fonctionnel, que je lance manuellement en exécutant un Launcher.java qui a une méthode principale et exécute le travail que j'ai défini (ce travail je l'ai défini dans un xml et je passe Cela fonctionne parfaitement bien, maintenant je cherche à le mettre en production et pour cela j'ai besoin de configurer ce processus pour courir tous les jours à une heure du matin en Espagne, comment puis-je faire cela? Ceci est mon lanceur (si je clic droit cours AS-> application Java, il fonctionne très bien, mais comment puis-je faire une course de lot comme je l'ai besoin?)Exécuter le lot automatiquement à l'aube
public final class Launcher {
private static final String LOG_DECORATOR = "****************************************.";
private static final Logger LOG = Logger.getLogger("batch");
private static final Long MIL = 1000L;
private Launcher(){
throw new UnsupportedOperationException();
}
public static void main(String[] args){
LOG.info(LOG_DECORATOR);
LOG.info(" INICIO DEL PROCESO ");
LOG.info(LOG_DECORATOR);
LOG.info("Cargando datos de configuracion");
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext(args[0]);
final PropertyFacade property = applicationContext.getBean(PropertyFacade.class);
Assert.notNull(property, "Datos de configuracion no cargados correctamente");
final String entorno = property.property("entorno");
LOG.info("Entorno: ".concat(entorno));
final JobLauncher jobLauncher = (JobLauncher) applicationContext.getBean("jobLauncher");
final Job job = (Job) applicationContext.getBean("job");
long tiempoComenzar;
long tiempoTerminar;
tiempoComenzar = System.currentTimeMillis();
try {
final JobExecution execution = jobLauncher.run(job, new JobParameters());
LOG.info("Job Status : " + execution.getStatus());
LOG.info("Job completed");
} catch (JobExecutionAlreadyRunningException e) {
LOG.info("Error Launcher: ".concat(e.toString()));
LOG.error("Exception Launcher",e);
} catch(IllegalArgumentException e){
LOG.info("Error Launcher: ".concat(e.toString()));
LOG.error("Exception Launcher",e);
} catch(JobInstanceAlreadyCompleteException e){
LOG.info("Error Launcher: ".concat(e.toString()));
LOG.error("Exception Launcher",e);
} catch(JobParametersInvalidException e){
LOG.info("Error Launcher: ".concat(e.toString()));
LOG.error("Exception Launcher",e);
} catch(JobRestartException e){
LOG.info("Error Launcher: ".concat(e.toString()));
LOG.error("Exception Launcher",e);
}finally {
((ConfigurableApplicationContext) applicationContext).close();
tiempoTerminar = System.currentTimeMillis();
final long tiempoDedicado = (tiempoTerminar - tiempoComenzar)/MIL;
LOG.info(
"Fin. Tiempo dedicado a la consulta: ".concat(String.valueOf(tiempoDedicado)).concat(" segundos."));
LOG.info(LOG_DECORATOR);
LOG.info(" FIN DEL PROCESO ");
LOG.info(LOG_DECORATOR);
}
}
}
C'est le Job
Je vous remercie de votre aide.
Votre code n'est pas pertinent à la question, ce qui * est * pertinent est: sur quel système d'exploitation votre code est-il exécuté? a-t-il un planificateur de tâches intégré? (comme cron par exemple) – alfasin
Merci de répondre, Exécuter sur Windows, non, je ne sais pas sur le programmeur de tâches c'est ce que j'essaie de comprendre ou de savoir faire, le travail exécute 3 étapes qui sont définies dans trois Des classes. Java (3task) – jaxonjma
Utiliser le quartz. il met en place un planificateur similaire à cron. http://www.quartz-scheduler.org/ – Dakoda