javajbossquartz-scheduler

Illegal access (Quartz with JBoss)


I am running a scheduled job in a web application which sometimes (could notreproduce it ) results in the following exception:

[WebappClassLoader] Illegal access: this web application instance has been stopped already. Could not load org.quartz.StatefulJob. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. java.lang.IllegalStateException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1244) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at org.quartz.JobDetail.class$(JobDetail.java:279) at org.quartz.JobDetail.isStateful(JobDetail.java:425) at org.quartz.simpl.RAMJobStore.triggerFired(RAMJobStore.java:1313) at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:342) 13:41:00,083 ERROR [STDERR] Exception in thread "DefaultQuartzScheduler_QuartzSchedulerThread" 13:41:00,083 ERROR [STDERR] java.lang.NoClassDefFoundError: org.quartz.StatefulJob 13:41:00,083 ERROR [STDERR] at org.quartz.JobDetail.class$(JobDetail.java:279) 13:41:00,083 ERROR [STDERR] at org.quartz.JobDetail.isStateful(JobDetail.java:425) 13:41:00,083 ERROR [STDERR] at org.quartz.simpl.RAMJobStore.triggerFired(RAMJobStore.java:1313) 13:41:00,083 ERROR [STDERR] at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:342)

There also a NoClassDefFoundError. It says that org.quartz.StatefulJob is not found. Here is how the job is scheduled:

 Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
 if (!sched.isStarted()){
     sched.start();
 }

 String konf = MyConfigClass.getRow(25).getKonfiguration();
 Calendar cal = Calendar.getInstance();
 cal.setTime(MyParser.stf.parse(konf));
 String expression = "0 " + cal.get(Calendar.MINUTE) + " " + cal.get(Calendar.HOUR_OF_DAY) + " ? * MON-FRI";
 CronTrigger ct = new CronTrigger(triggerName, group, jobName, group, expression);

 if (sched.getTrigger(triggerName, Scheduler.DEFAULT_GROUP) != null) {
     sched.rescheduleJob(triggerName, group, ct);
 } else {
     JobDetail jd = new JobDetail(jobName, group, MyJob.class);
     sched.scheduleJob(jd, ct);
 }

I do not know what could be the problem. First I thought that the session dies before the job executes, but I've tried it and that's no the case. The interesting thing is that after this exception, the job runs again with no problem.

Do you have any ideas?


Solution

  • It looks like your quartz job is trying to do something after your app was stopped. It might be trying to access some resources that were available while your app was running, but not anymore (something like getResourceAsStream maybe).

    It might help if you post more info: stacktraces, code of your job, etc.

    After update: Here is what I think is happening:

    The way I see it, you have two choices: