在JobDataMap中存储EJB后,Quartz触发器处于ERROR状态

问题描述 投票:0回答:1

我有一个启动单例EJB,而不是初始化调度程序并将EJB存储在JobDataMap中。当我存储EJB时,触发器进入ERROR状态。

@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类,它实现了使用@Stateless注释的Serializable接口。

java java-ee quartz-scheduler
1个回答
0
投票

最后发现,在注入EJB的持久化过程中,这是一个序列化问题。解决方案是改变实现并使用JNDI查找在Job中获取EJB。

© www.soinside.com 2019 - 2024. All rights reserved.