У меня есть загрузочный одноэлементный EJB, который инициализирует планировщик и сохраняет EJB в JobDataMap.Триггер переходит в состояние ОШИБКА, когда я сохраняю EJB.
@Singleton
@Startup
@Lock(LockType.READ)
public class NotificationScheduler {
private Scheduler scheduler;
@Inject
private QuartzProperties quartzProperties;
@Inject
private NotificationMailProcess notificationMailProcess;
@PostConstruct
public void init() {
try {
Properties properties = new Properties();
properties.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "NotificationScheduler");
properties.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_ID, StdSchedulerFactory.AUTO_GENERATE_INSTANCE_ID);
properties.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, quartzProperties.getQuartzThreadPoolClass());
properties.put(StdSchedulerFactory.PROP_THREAD_POOL_PREFIX + ".threadCount", quartzProperties.getQuartzThreadPoolCount());
properties.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, quartzProperties.getQuartzJobStoreClass());
properties.put(StdSchedulerFactory.PROP_JOB_STORE_PREFIX + ".driverDelegateClass",
quartzProperties.getQuartzJobStoreDriverDelegateClass());
properties.put(StdSchedulerFactory.PROP_JOB_STORE_PREFIX + ".dataSource", quartzProperties.getQuartzJobStoreDataSource());
properties.put("org.quartz.dataSource." + quartzProperties.getQuartzJobStoreDataSource() + ".jndiURL",
quartzProperties.getQuartzJobStoreDataSource());
properties.put(StdSchedulerFactory.PROP_JOB_STORE_PREFIX + ".nonManagedTXDataSource",
quartzProperties.getQuartzJobStoreNonManagedTXDataSource());
properties.put("org.quartz.dataSource." + quartzProperties.getQuartzJobStoreNonManagedTXDataSource() + ".jndiURL",
quartzProperties.getQuartzJobStoreNonManagedTXDataSource());
properties.put(StdSchedulerFactory.PROP_JOB_STORE_PREFIX + ".isClustered", quartzProperties.getQuartzJobStoreIsClustered());
properties.put(StdSchedulerFactory.PROP_JOB_STORE_PREFIX + ".clusterCheckinInterval",
quartzProperties.getQuartzJobStoreClusterCheckinInterval());
StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
schedulerFactory.initialize(properties);
scheduler = schedulerFactory.getScheduler();
scheduler.start();
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("process", notificationMailProcess);
JobDetail notificationMailJobDetail = newJob(NotificationMailJob.class) .withIdentity(Constants.JOB_NAME,Constants.JOB_GROUP).usingJobData(jobDataMap).build();
String cronExpression = Constants.CONFIGURATION_DEFAULT_JOB_CRON);
Trigger trigger = newTrigger().withIdentity(Constants.JOB_TRIGGER, Constants.JOB_GROUP)
.withSchedule(cronSchedule(cronExpression)).build();
scheduler.scheduleJob(notificationMailJobDetail, new HashSet<>(Arrays.asList(trigger)), true);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
NotificationMailProcess - это фиктивный класс EJB, который реализует интерфейс Serializable с аннотацией @ Stateless.