Bonjour, je suis sur un projet JEE glassfish maven3,
J'ai une cron qui s’exécute automatiquement toute les 20 secondes.
Maintenant j'aimerais que cette cron soit synchroniser entre les différentes instances de cette même cron.

J'ai essayer en synchronisant la méthode mais cela ne marche pas.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
 
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
 
 
public class SchedulerJob implements Job{
 
 
 
    @Override
    public synchronized void execute(JobExecutionContext jec) throws JobExecutionException {
// la tache
}
Ma configuration :

Mon scheduler : qui lance ma tache toute les 30 secondes.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
public class QuartzSchedulerListener implements ServletContextListener {
 
    private  JobDetail job;
    private Trigger trigger;
    private Scheduler scheduler;
 
    @Override
    public void contextInitialized(ServletContextEvent sce) {
         job = JobBuilder.newJob(SchedulerJob.class)
                .withIdentity("anyJobName", "group1").build();
 
        try {
 
             trigger = TriggerBuilder.newTrigger().withIdentity("anyTriggerName", "group1")
                    .withSchedule(
                    CronScheduleBuilder.cronSchedule("0/30 * * * * ?")).build();
 
            scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.start();
            scheduler.scheduleJob(job, trigger);
 
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
 
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        try {
 
            scheduler.shutdown();
            // throw new UnsupportedOperationException("Not supported yet.");
        } catch (SchedulerException ex) {
           ex.printStackTrace();
        }
    }
}
Mon web.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
  <listener>
        <listener-class>
            com.package.test.task.QuartzSchedulerListener
        </listener-class>
    </listener>

Ma question est simple y a t'il un moyen de synchroniser les différentes instances de ma class SchedulerJob ? J'ai tester en mettent synchronized sur la méthode il se passe la même chose et ma tache est relancé, et j'ai donc 2 instance de ma classe.


Merci de m'avoir lu.
Cordialement.