Using CDI in Quartz Jobs

I would like to know if CDI beans can be used in Quartz jobs in a portable manner?

I already tried to write my own JobFactory, etc., but the problem is that the BeanManager is not available via JNDI because the job is running on a non-managed thread. My application server is Websphere 8.0.0.1 and I already read that this is against the EE6 spec so that the name "java:" is available for non-managed threads.

There are two solutions now:

  • Let Websphere create workflows (not sure how to do this, any help would be nice)
  • Implement an EJB and call the method via EJBJobInvoker

I know that when I use the CDI solution I cannot let the worker threads run in another JVM, correct me if I am wrong. To stay scalable, should I implement an EJB to do this? Do you think you had this problem? I would also appreciate different solutions or even suggestions in different scheduler libraries!

+2


source to share


4 answers


Take a look at the DeltaSpike scheduler module .



You can find the latest version on the Maven Central Repository .

+3


source


You can take a look at DeltaSpike and use its BeanManagerProvider, or you can create a PortableExtension and cache the BeanManager reference in the extension and use that. There should be no problem with this.



+1


source


There seems to be an easy way in a CD environment with a local Quartz environment: set your own PropertySettingJobFactory subclass in your scheduler, which has its own injected BeanManager instance and does the following for each job created:

        Job job = super.newJob(bundle, Scheduler);
        Class<? extends Job> clazz = job.getClass();

        if (beanManager != null) {
            CreationalContext<Job> ctx = beanManager
                .createCreationalContext(null);

            @SuppressWarnings("unchecked")
            AnnotatedType<Job> type = (AnnotatedType<Job>) beanManager
                .createAnnotatedType(clazz);

            InjectionTarget<Job> it = beanManager.createInjectionTarget(type);

            it.inject(job, ctx);
        }

      

Then @Injects will be populated with your works when created.

+1


source


Do you look at CDIQI for your CDI Quartz implementation that you can model after?

https://github.com/symbiont/cdiqi

Or is your problem that you absolutely need to create your own themes? CDIQI has asynchronous job execution, but it looks like you want to remotely run your version on a different JVM?

0


source







All Articles