views:

132

answers:

1

Hi, 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?

+1  A: 

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:

  • You schedule your job successfully
  • For whatever reason your webapp is stopped. I would search JBoss logs for a reason.
  • At this moment time comes to execute your job (org.quartz.simpl.RAMJobStore.triggerFired(RAMJobStore.java:1313))
  • This call goes down to isStateful method of JobDetail class
  • The method has this code in it return (StatefulJob.class.isAssignableFrom(jobClass));
  • StatefulJob class was not loaded before. Your classLoader tries to load it (org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204))
  • Since your webapp was stopped, you are getting exception

The way I see it, you have two choices:

  • Ignore this problem, since there is nothing you can do to make quartz work after your webapp was stopped
  • Try to figure out what causes your webapp to stop and fix it
Georgy Bolyuba
I have read on other forums that this error is typically caused by a stopped application, but the thing is that our application was not stopped when the error was thrown. As I said I tried to kill the session, ie. put a time-out that would expire (I taught that this would close some resources for the job) before the job executes, but it was executed without any errors even if the session expired.
Atticus
Closing session is not the same as stopping webapp. In your code I do not see anything related to the session. So, expiring sessions will not help track the problem I think.
Georgy Bolyuba
The interesting thing is that after this exception has occurred the job runs again and it manages to finish. Maybe some resources are not available when trying to run the job, but then it accesses them and runs the job. BTY is quartz able to do such thing, I mean rerun failed jobs?
Atticus
If you job throws an exception, quartz will simply ignore it and call your job again on schedule. Resources that are not available: StatefulJob class. Maybe your webapp is reloaded for some reason. In any case I would check your JBoss logs for anything related to reload/stop of your webapp
Georgy Bolyuba
I did not find anything related to reload/stop in the JBoss logs. When I see the error again I will check the logs.Anyway, thanks for your effort.
Atticus