Ошибка при остановке Tomcat 8 QuarzListener Java EE

360
21 мая 2017, 21:36

Поставил Quartz. Создал слушателя, "работу". добавил в web.xml своего слушателя:

<listener>
       <listener-class>com.site.cron.Cron</listener-class>
   </listener>

при остановке tomcat8 получаю такое:

19-May-2017 22:01:19.164 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.
19-May-2017 22:01:19.164 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
19-May-2017 22:01:19.218 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]
19-May-2017 22:01:19.270 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
Context Destroyed
19-May-2017 22:01:19.307 WARNING [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [DefaultQuartzScheduler_QuartzSchedulerThread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:410)
19-May-2017 22:01:19.319 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
19-May-2017 22:01:19.321 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
19-May-2017 22:01:19.321 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
19-May-2017 22:01:19.323 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]
19-May-2017 22:01:36.160 INFO [DefaultQuartzScheduler_QuartzSchedulerThread] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load [org.quartz.DisallowConcurrentExecution]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
 java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org.quartz.DisallowConcurrentExecution]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1305)
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1293)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1158)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    at org.quartz.impl.JobDetailImpl.isConcurrentExectionDisallowed(JobDetailImpl.java:388)
    at org.quartz.simpl.RAMJobStore.acquireNextTriggers(RAMJobStore.java:1428)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:272)
Exception in thread "DefaultQuartzScheduler_QuartzSchedulerThread" java.lang.NoClassDefFoundError: org/quartz/DisallowConcurrentExecution
    at org.quartz.impl.JobDetailImpl.isConcurrentExectionDisallowed(JobDetailImpl.java:388)
    at org.quartz.simpl.RAMJobStore.acquireNextTriggers(RAMJobStore.java:1428)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:272)
Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has been stopped already. Could not load [org.quartz.DisallowConcurrentExecution]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1295)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1158)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    ... 3 more
Caused by: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org.quartz.DisallowConcurrentExecution]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1305)
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1293)
    ... 5 more

Код:

главный класс:

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Date;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;
@WebListener()
public class Cron implements ServletContextListener,
        HttpSessionListener, HttpSessionAttributeListener {
    Scheduler scheduler = null;
    // Public constructor is required by servlet spec
    public Cron() {}
    // -------------------------------------------------------
    // ServletContextListener implementation
    // -------------------------------------------------------
    public void contextInitialized(ServletContextEvent sce) {
        try {
            String exp = "0 0/1 * 1/1 * ? *";
            JobDetail job = JobBuilder.newJob(CronJob.class).withIdentity("myjob").build();
            Trigger trigger = TriggerBuilder.newTrigger().withSchedule(CronScheduleBuilder.cronSchedule(exp)).build();
            SchedulerFactory schFactory = new StdSchedulerFactory();
            Scheduler scheduler = schFactory.getScheduler();
            scheduler.start();
            scheduler.scheduleJob(job, trigger);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        /*
        try {
            *//*SchedulerFactory sf = new StdSchedulerFactory();
            Scheduler sched = sf.getScheduler();*//*
            // Setup the Job class and the Job group
            JobDetail job = newJob(CronJob.class).withIdentity("CronQuartzJob", "Group").build();
            Date startTime = DateBuilder.nextGivenSecondDate(null, 15);
            // Create a Trigger that fires every 5 minutes.
            //Trigger trigger = newTrigger().withIdentity("TriggerName", "Group").withSchedule(simpleSchedule().withIntervalInSeconds(30)).forJob(job).build();
            SimpleTrigger trigger = (SimpleTrigger) newTrigger().withIdentity("JOB", "Group").startAt(startTime).withSchedule(simpleSchedule().withIntervalInSeconds(86400).repeatForever()).build();
            // Setup the Job and Trigger with Scheduler & schedule jobs
            scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.scheduleJob(job, trigger);
            scheduler.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }*/
    }
    public void contextDestroyed(ServletContextEvent sce) {
      /* This method is invoked when the Servlet Context
         (the Web application) is undeployed or
         Application Server shuts down.
      */
        System.out.println("Context Destroyed");
        try {
            scheduler.shutdown();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
    // -------------------------------------------------------
    // HttpSessionListener implementation
    // -------------------------------------------------------
    public void sessionCreated(HttpSessionEvent se) {
      /* Session is created. */
    }
    public void sessionDestroyed(HttpSessionEvent se) {
      /* Session is destroyed. */
    }
    // -------------------------------------------------------
    // HttpSessionAttributeListener implementation
    // -------------------------------------------------------
    public void attributeAdded(HttpSessionBindingEvent sbe) {
      /* This method is called when an attribute
         is added to a session.
      */
    }
    public void attributeRemoved(HttpSessionBindingEvent sbe) {
      /* This method is called when an attribute
         is removed from a session.
      */
    }
    public void attributeReplaced(HttpSessionBindingEvent sbe) {
      /* This method is invoked when an attibute
         is replaced in a session.
      */
    }
}

Работа:

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class CronJob implements Job {
    @Override
    public void execute(JobExecutionContext ctx) throws JobExecutionException {
        System.out.println("Hello World");
    }
}
READ ALSO
Как создать &ldquo;древовидные&rdquo; массивы в JSON?

Как создать “древовидные” массивы в JSON?

Я понимаю как "распарсить" строку json в которой есть древовидная структура, но не могу понять, как создать дополнительные массивы в определенной...

284
Удаление комментариев из javа-программы

Удаление комментариев из javа-программы

Из текста java-программы удалить комментарии вида // и /*Новый текст записать в тот же файл

409
In-app purchase android

In-app purchase android

ЗдравствуйтеВнедрил гугловский пример для покупок в приложении TrivialDrive в свое приложение

316
Не уверен в мощности JSON

Не уверен в мощности JSON

На Java надо написать прогруммку, которая забьет текстовый файл инфой в формате Json40000 Json обьектов, в каждом примерно 1000 символов

295