SPR-6354 DefaultLifecycleProcessor no longer waits for the shutdown of SmartLifecycle beans that are not actually running.

This commit is contained in:
Mark Fisher 2009-11-20 18:09:14 +00:00
parent 6653f25e81
commit c6f3613411
3 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,60 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.scheduling.quartz;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.StopWatch;
/**
* @author Mark Fisher
* @since 3.0
*/
public class QuartzSchedulerLifecycleTests {
@Test // SPR-6354
public void destroyLazyInitSchedulerWithDefaultShutdownOrderDoesNotHang() {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", this.getClass());
assertNotNull(context.getBean("lazyInitSchedulerWithDefaultShutdownOrder"));
StopWatch sw = new StopWatch();
sw.start("lazyScheduler");
context.destroy();
sw.stop();
System.out.println(sw.getTotalTimeMillis());
assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
}
@Test // SPR-6354
public void destroyLazyInitSchedulerWithCustomShutdownOrderDoesNotHang() {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", this.getClass());
assertNotNull(context.getBean("lazyInitSchedulerWithCustomShutdownOrder"));
StopWatch sw = new StopWatch();
sw.start("lazyScheduler");
context.destroy();
sw.stop();
System.out.println(sw.getTotalTimeMillis());
assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="lazyInitSchedulerWithDefaultShutdownOrder" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="true"/>
<bean id="lazyInitSchedulerWithCustomShutdownOrder" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="true">
<property name="shutdownOrder" value="99"/>
</bean>
</beans>

View File

@ -174,6 +174,10 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
bean.stop();
}
}
else if (bean instanceof SmartLifecycle) {
// don't wait for beans that aren't running
latch.countDown();
}
lifecycleBeans.remove(beanName);
}
}