Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ava.lang.IllegalStateException: Illegal access - on stop tomcat8 #144

Closed
Tsyklop opened this issue May 20, 2017 · 2 comments
Closed

ava.lang.IllegalStateException: Illegal access - on stop tomcat8 #144

Tsyklop opened this issue May 20, 2017 · 2 comments
Labels
stale Inactive items that will be automatically closed if not resurrected

Comments

@Tsyklop
Copy link

Tsyklop commented May 20, 2017

Quartz 2.2.3
I run tomcat 8 and listener:

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.
      */
    }
}

Job:

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");
    }
}

But when i stop tomcat8, i get error:

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

web.xml:

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

   <context-param>
       <param-name>quartz:config-file</param-name>
       <param-value>quartz.properties</param-value>
   </context-param>
   <context-param>
       <param-name>quartz:shutdown-on-unload</param-name>
       <param-value>true</param-value>
   </context-param>
   <context-param>
       <param-name>quartz:wait-on-shutdown</param-name>
       <param-value>true</param-value>
   </context-param>
   <context-param>
       <param-name>quartz:start-on-load</param-name>
       <param-value>true</param-value>
   </context-param>

what wrong?

@soheilrahsaz
Copy link

check this link: https://stackoverflow.com/a/3398874/9213957

@stale
Copy link

stale bot commented Aug 2, 2021

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale Inactive items that will be automatically closed if not resurrected label Aug 2, 2021
@Tsyklop Tsyklop closed this as completed Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Inactive items that will be automatically closed if not resurrected
Projects
None yet
Development

No branches or pull requests

3 participants