In this tutorial you will learn about Register Shutdown Hook of Spring Framework
In this tutorial you will learn about Register Shutdown Hook of Spring FrameworkIf you are using Spring IoC in non web application and want to gracefully downdown all resources we use registerShutdownHook(). This method calls the relevant destroy methods. In order to register a shutdown hook, you have to call the the registerShutdownHook() method which found in the AbstractApplicationContext class.
AppMain.java
package com.roseindia.common; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class AppMain { public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "context.xml" }); System.out.println("Add a shutdown hook for the above context"); context.registerShutdownHook(); } }
context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
|
Add a shutdown hook for the above context Sep 3, 2010 3:04:24 PM org.springframework.context.support.AbstractApplicationContext doClose INFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@18a47e0: startup date [Fri Sep 03 15:04:24 GMT+05:30 2010]; root of context hierarchy |