1

I'm using Quartz 2.1.1 and have a JAR application (Note, not a web so I don't have Spring). I'm running my app on JBoss 4.2.2 (cannot change this). I want to schedule my job to run every 5 minutes, but prefer not to create a scheduler through a static block. It doesn't seem to be working anyway. In my Job class, I have ...

static {
    LOG.info("Started static process orders job at " + (new java.util.Date()).toString());

    final JobDetail job = JobBuilder.newJob(ProcessOrdersJob.class).withIdentity("processOrdersJob", "group1").build();

    final Trigger trigger = TriggerBuilder
            .newTrigger()
            .withIdentity("processOrdesrTrigger", "group1")
            .withSchedule(
                    CronScheduleBuilder
                            .cronSchedule("0 5,10,15,20,25,30,35,40,45,50,55 * * * ?"))
            .build();

    Scheduler scheduler;
    try {
        scheduler = new StdSchedulerFactory().getScheduler();
        scheduler.start();
        scheduler.scheduleJob(job, trigger);
    } catch (SchedulerException e) {
        LOG.error(e.getMessage(), e);
        e.printStackTrace(System.err);
    }
} // static

but it doesn't appear to be run (the log never contains the info message). Does anyone know a more flexible way of configuring my Quartz job in my JAR for deployment to JBoss?

Thanks, -

Edit: I tried Rosdi's suggestion, reverting the Quartz used by my Maven build to 1.5.2 (the same version that JBoss had installed), but alas, got the exception

javax.ejb.EJBTransactionRolledbackException: java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;
    at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
    at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
    at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:249)
    at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
    at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
    at $Proxy113.execute(Unknown Source)
    at org.jboss.resource.adapter.quartz.inflow.QuartzJob.execute(QuartzJob.java:57)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;
    at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:174)
    at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
    ... 11 more
Caused by: java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;
    at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.<clinit>(BeanValidationIntegrator.java:53)
    at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:46)
    at org.hibernate.service.internal.BootstrapServiceRegistryImpl.<init>(BootstrapServiceRegistryImpl.java:80)
    at org.hibernate.service.internal.BootstrapServiceRegistryImpl.<init>(BootstrapServiceRegistryImpl.java:57)
    at org.hibernate.service.ServiceRegistryBuilder.<init>(ServiceRegistryBuilder.java:76)
    at org.mainco.subco.dido.service.AbstractServiceProvider.getSessionFactory(AbstractServiceProvider.java:67)
    at org.mainco.subco.dido.service.AbstractServiceProvider.initServices(AbstractServiceProvider.java:118)
    at org.mainco.subco.dido.quartz.ProcessOrdersJob.execute(ProcessOrdersJob.java:92)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
STW
  • 44,917
  • 17
  • 105
  • 161
Dave
  • 15,639
  • 133
  • 442
  • 830

1 Answers1

0

This is what I use for my JBoss 5, I dont know whether it will work under JBoss 4.

package whatever;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;

import org.jboss.ejb3.annotation.Depends;
import org.jboss.ejb3.annotation.ResourceAdapter;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@MessageDriven(activationConfig = {@ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0/30 * * * * ?")})
@ResourceAdapter("quartz-ra.rar")
@Depends({
"jboss.ejb:service=EJBTimerService""})
public class MyClass implements StatefulJob {

private static final Logger log = LoggerFactory.getLogger(MyClass.class);

public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    log.debug("Job started at: " + new Date());
    this.process();
    log.debug("Job completed at: " + new Date());
}

private void process() {
    //do whatever you want to do
}

}

Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154
  • Thanks for your suggestion but when I tried it, I got the bizarre NoSuchMethodError I included above. Not sure where its all falling apart. – Dave Aug 07 '12 at 00:45
  • @Dave, try to remove the log, (`org.slf4j.Logger`, `org.slf4j.LoggerFactory`) and see whether it works. – Rosdi Kasim Aug 07 '12 at 03:11
  • I've gotten a little closer with this. The error is caused by JBoss' hibernate libraries being used over the ones packaged with my JAR file. Is there a way I can get JBoss to accept my Hibernate libraries over its own -- in the structure of a JAR? – Dave Aug 09 '12 at 13:41
  • @Dave I am pretty sure you can, you set that in `META-INF/jboss-classloading.xml`. Refer here, this guy can explain it better than I could: http://phytodata.wordpress.com/2010/10/21/demystifying-the-jboss5-jboss-classloading-xml-file/ – Rosdi Kasim Aug 09 '12 at 14:16
  • @Dave I forgot you are using JBoss 4, try here if the above link does not help, https://community.jboss.org/wiki/ClassLoadingConfiguration, sorry I never work on JBoss 4 so could not help much. – Rosdi Kasim Aug 09 '12 at 14:23
  • Thanks, there were indeed classloader issues that I got fixed through the use of a jboss.xml file in my META-INF directory. That aside, your Quartz configuration worked perfectly. – Dave Aug 10 '12 at 18:24
  • @Dave In that case you might be interested to answer this question, http://stackoverflow.com/questions/11908720/how-to-configure-a-war-in-order-to-depends-on-the-exported-libraries-in-the-war, I want to know the answer to it too... – Rosdi Kasim Aug 10 '12 at 22:17