2010-04-28 9 views
14

Durante el desarrollo de un planificador basado en la primavera en un contenedor Tomcat, siempre conseguir este logoutput en la aplicación web o el cierre anular la implementación de servidor:primavera de error Programador de apagado

Apr 28, 2010 4:21:33 PM org.apache.catalina.core.StandardService stop 
INFO: Stopping service Catalina 
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads 
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1] but has failed to stop it. This is very likely to create a memory leak. 
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads 
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-2] but has failed to stop it. This is very likely to create a memory leak. 
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads 
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-3] but has failed to stop it. This is very likely to create a memory leak. 
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads 
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-4] but has failed to stop it. This is very likely to create a memory leak. 
Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads 
SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-5] but has failed to stop it. This is very likely to create a memory leak. 
. 
. 
.  
SEVERE: A web application created a ThreadLocal with key of type [org.springframework.core.NamedThreadLocal] (value [Prototype beans currently in creation]) and a value of type [null] (value [null]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed. 
Apr 28, 2010 4:21:34 PM org.apache.coyote.http11.Http11Protocol destroy 
INFO: Stopping Coyote HTTP/1.1 on http-8606 

¿Cómo puedo solucionar este problema?

agradecimiento stevedbrown

añado este escucha a mi webapp

public class ShutDownHook implements ServletContextListener { 
    @Override 
    public void contextDestroyed(ServletContextEvent arg0) { 
     BeanFactory bf = (BeanFactory) ContextLoader.getCurrentWebApplicationContext(); 
     if (bf instanceof ConfigurableApplicationContext) { 
      ((ConfigurableApplicationContext)bf).close(); 
     } 
    } 

    @Override 
    public void contextInitialized(ServletContextEvent arg0) { 
    } 
} 

y mi web.xml

<listener> 
    <listener-class>pkg.utility.spring.ShutDownHook</listener-class> 
</listener> 

pero el error sigue ahí.

primavera config:

<bean id="run" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 
    <property name="concurrent" value="false" /> 
    <property name="targetObject" ref="scheduler" /> 
    <property name="targetMethod" value="task" /> 
</bean> 

<bean id="cronTrg" class="org.springframework.scheduling.quartz.CronTriggerBean"> 
    <property name="jobDetail" ref="run" /> 
    <property name="cronExpression" value="0/5 * * * * ?" /> 
</bean> 

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy"> 
    <property name="triggers"> 
     <list> 
      <ref bean="cronTrg" /> 
     </list> 
    </property> 
</bean> 
+0

hey Alex, ¿Tienes alguna solución para este problema? – Joe

Respuesta

2

es necesario agregar un gancho de cierre - ver Registering a shutdown hook in Spring 2.5.

En su caso, probablemente deba agregar un escucha de contexto a su aplicación web que hace esto (entrada web.xml para el oyente + clase de implementación).

Uso cercano, es más fácil.

((YourClass)yourObject).close(); 
+0

Agrego el oyente pero no pasa nada. – Alex

+1

Desea ((ConfigurableApplicationContext) bf) .close() ;, not ((ConfigurableApplicationContext) bf) .registerShutdownHook(); a menos que realmente desee registrar el gancho de apagado con su tiempo de ejecución [bueno para junit] (Runtime.getRuntime().addShutdownHook (nueva Thread() { public void run() {si (CTX instanceof ConfigurableApplicationContext) { ((ConfigurableApplicationContext) CTX) .close(); }} }); ) – stevedbrown

+0

No tengo claro qué objeto debo cerrar, agregué la configuración de muelles y modifiqué mi clase de oyentes. – Alex

2

Aquí está mi solución ya que ninguno de los que encontré en línea funcionó. Esto es específicamente para apagar el programador de cuarzo con la primavera & Tomcat

Mi explicación está aquí: http://forum.springsource.org/showthread.php?34672-Quartz-doesn-t-shutdown&p=370060#post370060

Básicamente lo que el problema parecía ser que es cuarzo no tiene suficiente tiempo para el apagado limpiamente y el argumento waitForJobsToCompleteOnShutdown doesn Parece que ayuda. Así que implementé un oyente de apagado personalizado en la aplicación web, obtengo una referencia al programador y lo apago manualmente. Y luego espere 1 segundo antes de continuar.

public class ShutDownHook implements ServletContextListener 
{ 

    @Override 
    public void contextDestroyed(ServletContextEvent arg0) 
    { 
     try 
     { 
      // Get a reference to the Scheduler and shut it down 
      WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext(); 
      Scheduler scheduler = (Scheduler) context.getBean("quartzSchedulerFactory"); 
      scheduler.shutdown(true); 

      // Sleep for a bit so that we don't get any errors 
      Thread.sleep(1000); 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 

    @Override 
    public void contextInitialized(ServletContextEvent arg0) 
    { 
    } 
5

Imho esto es un problema del programador de cuarzo. Archivé un error https://jira.terracotta.org/jira/browse/QTZ-192. Como solución alternativa, la solución Sleep() sugerida por Colin Peters funciona para mí. Para no provoca el cierre de dos veces también se podría añadir el sueño a SchedulerFactoryBean de primavera:

import org.quartz.SchedulerException; 
import org.springframework.scheduling.quartz.SchedulerFactoryBean; 

public class SchedulerFactoryBeanWithShutdownDelay extends SchedulerFactoryBean{ 

    @Override 
    public void destroy() throws SchedulerException { 
    super.destroy(); 
    // TODO: Ugly workaround for https://jira.terracotta.org/jira/browse/QTZ-192 
    try { 
     Thread.sleep(1000); 
    } catch(InterruptedException e) { 
     throw new RuntimeException(e); 
    } 
    } 
} 
+2

El problema del cuarzo se soluciona con Quartz 2.1. Desafortunadamente, Spring 3.1 está basado en Quartz 1.8 y una actualización a 2.0 se considera para Spring 3.2 como muy pronto. Fuente: https://jira.springsource.org/browse/SPR-7987 – StefanR

+1

Actualmente Spring 3.1 es compatible con Quartz 2.x http://www.infoq.com/news/2011/10/spring-3.1-rc1-release – bmurmistro

+0

Me he actualizado a SpringFramework 4.1.6.RELEASE y Quartz 2.1.7 y todavía tenía que hacer este trabajo en ... – TungstenX

Cuestiones relacionadas