How to add shutdown hook in CQ5
Hi there,
There is a case for me: i need to persist application some data before JVM shutdown. So i program as below in OSGI bundle:
protected void activate(ComponentContext ctx) { this.bundleContext = ctx.getBundleContext(); final Set<JobBean> jobs = CreateJobServlet.jobNames; jobs.addAll(getInProgressJob()); shutDownHook(jobs); } private Set<JobBean> getInProgressJob() { return getCustomerService().getInProgressJob(); } private void shutDownHook(final Set<JobBean> jobs) { logger.info("Exec shutDownHook()........."); Runtime.getRuntime().addShutdownHook(new Thread(){ public void run(){ logger.info("Running shutdown hook before JVM complete closed......"); getCustomerService().persisJob(jobs); } }); }However, the function shutDownHook never enter and work, no any log info in background.
Anyone know how to do that? thanks a lot
Brian