01: package com.whirlycott.cache.test;
02:
03: import com.whirlycott.cache.Cache;
04: import com.whirlycott.cache.CacheException;
05: import com.whirlycott.cache.CacheManager;
06:
07: public class TestShutdown {
08:
09: //
10: // Inner class
11: //
12:
13: class ShutdownHook extends Thread {
14: public ShutdownHook() {
15: super ();
16: }
17:
18: public void run() {
19: System.out.println("Shutdown hook running");
20: try {
21: CacheManager.getInstance().shutdown();
22: } catch (CacheException e) {
23: // TODO Auto-generated catch block
24: e.printStackTrace();
25: }
26: }
27: }
28:
29: public static void main(String[] args_) throws CacheException {
30: for (int i = 0; i < args_.length; i++) {
31: System.out.println(">>args[" + i + "]:" + args_[i]);
32: }
33:
34: /* if (args_.length != 1) {
35: System.out.println("Usage: <JVM> TestShutdown <config> log4j.properties <config>");
36: System.out.println("where <config> is the configuration file.");
37: System.exit(1);
38: }*/
39:
40: // PropertyConfigurator.configure(args_[0]);
41: TestShutdown test = new TestShutdown();
42: test.doIt();
43: }
44:
45: public TestShutdown() {
46: super ();
47:
48: ShutdownHook shutdownHook = new ShutdownHook();
49: Runtime.getRuntime().addShutdownHook(shutdownHook);
50: }
51:
52: private void doIt() {
53: try {
54: final Cache c = CacheManager.getInstance().getCache();
55: c.store("hey", "there");
56: } catch (CacheException e) {
57: e.printStackTrace();
58: }
59:
60: try {
61: System.out.println("3 seconds till shutdown...");
62: Thread.sleep(3000);
63: } catch (InterruptedException e) {
64: e.printStackTrace();
65: }
66: }
67:
68: }
|