Tomcat で Wicket Web アプリケーションを実行しています。アプリケーションは、(org.springframework.web.context.ContextLoaderListener を介して) Spring を使用してアプリケーションを初期化します。これは起動には問題ありませんが、生成されたスレッドをシャットダウンできるように、コンテキストが破棄されているという何らかの通知を受け取ることも望んでいます。そのような通知を受け取る方法はありますか? 私の質問の理解を助けるために、私のアプリケーションからの抜粋を含めました.
web.xml 抽出
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/mysite/web/spring/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
Spring applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="MyWebService" class="com.mysite.web.MyWebApp">
</bean>
</beans>
MyWebApp.java 抽出
public class MyWebApp extends org.apache.wicket.protocol.http.WebApplication {
private MyWebServiceServiceAPI webservice =
MyWebServiceAppImpl.getMyWebService();
public MyWebServiceWebApp() {
}
@Override
public void init() {
super.init();
webservice.start();
}
}
MyWebServiceAppImpl.java 抽出
public class MyWebServiceAppImpl extends ServiceImpl
implements MyWebServiceServiceAPI {
// The ServiceImpl implements the Callable<T> interface
private static MyWebServiceServiceAPI instance;
private List<Future<ServiceImpl>> results =
new ArrayList<Future<ServiceImpl>>();
private ExecutorService pool = Executors.newCachedThreadPool();
private MyWebServiceAppImpl() {
super(.....);
}
public synchronized static MyWebServiceServiceAPI getMyWebService() {
if (instance == null) {
instance = new MyWebServiceAppImpl();
instance.start();
}
return instance;
}
@Override
public synchronized void start() {
if (!started()) {
pool.submit(this);
super.start();
}
}