Source Code Cross Referenced for ShutdownHook.java in  » Database-JDBC-Connection-Pool » proxool » org » logicalcobwebs » proxool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » proxool » org.logicalcobwebs.proxool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This software is released under a licence similar to the Apache Software Licence.
003:         * See org.logicalcobwebs.proxool.package.html for details.
004:         * The latest version is available at http://proxool.sourceforge.net
005:         */
006:        package org.logicalcobwebs.proxool;
007:
008:        import org.apache.commons.logging.Log;
009:        import org.apache.commons.logging.LogFactory;
010:
011:        import java.lang.reflect.Method;
012:        import java.lang.reflect.InvocationTargetException;
013:
014:        /**
015:         * This is instantiated statically by ProxoolFacade. It will automatically
016:         * close down all the connections when the JVM stops.
017:         * @version $Revision: 1.13 $, $Date: 2006/11/02 10:00:34 $
018:         * @author bill
019:         * @author $Author: billhorsman $ (current maintainer)
020:         * @since Proxool 0.7
021:         */
022:        class ShutdownHook implements  Runnable {
023:
024:            private static final Log LOG = LogFactory
025:                    .getLog(ShutdownHook.class);
026:
027:            private static boolean registered;
028:
029:            protected static void init() {
030:                if (!registered) {
031:                    registered = true;
032:                    new ShutdownHook();
033:                }
034:            }
035:
036:            protected static void remove(Thread t) {
037:                Runtime runtime = Runtime.getRuntime();
038:                try {
039:                    final Method removeShutdownHookMethod = Runtime.class
040:                            .getMethod("removeShutdownHook",
041:                                    new Class[] { Thread.class });
042:                    removeShutdownHookMethod
043:                            .invoke(runtime, new Object[] { t });
044:                    if (LOG.isDebugEnabled()) {
045:                        LOG.debug("Removed shutdownHook");
046:                    }
047:                } catch (NoSuchMethodException e) {
048:                    LOG
049:                            .warn("Proxool will have to be shutdown manually with ProxoolFacade.shutdown() because this version of the JDK does not support Runtime.getRuntime().addShutdownHook()");
050:                } catch (SecurityException e) {
051:                    LOG.error("Problem removing shutdownHook", e);
052:                } catch (IllegalAccessException e) {
053:                    LOG.error("Problem removing shutdownHook", e);
054:                } catch (InvocationTargetException e) {
055:                    // Use getTargetException() because getCause() is only supported in JDK 1.4 and later
056:                    Throwable cause = ((InvocationTargetException) e)
057:                            .getTargetException();
058:                    if (cause instanceof  IllegalStateException) {
059:                        // This is probably because a shutdown is in progress. We can
060:                        // safely ignore that.
061:                    } else {
062:                        LOG.error("Problem removing shutdownHook", e);
063:                    }
064:                }
065:            }
066:
067:            /**
068:             * Registers this ShutdownHook with Runtime
069:             */
070:            private ShutdownHook() {
071:                Thread t = new Thread(this );
072:                t.setName("ShutdownHook");
073:                Runtime runtime = Runtime.getRuntime();
074:                try {
075:                    Method addShutdownHookMethod = Runtime.class.getMethod(
076:                            "addShutdownHook", new Class[] { Thread.class });
077:                    addShutdownHookMethod.invoke(runtime, new Object[] { t });
078:                    ProxoolFacade.setShutdownHook(t);
079:                    if (LOG.isDebugEnabled()) {
080:                        LOG.debug("Registered shutdownHook");
081:                    }
082:                } catch (NoSuchMethodException e) {
083:                    LOG
084:                            .warn("Proxool will have to be shutdown manually with ProxoolFacade.shutdown() because this version of the JDK does not support Runtime.getRuntime().addShutdownHook()");
085:                } catch (SecurityException e) {
086:                    LOG.error("Problem registering shutdownHook", e);
087:                } catch (IllegalAccessException e) {
088:                    LOG.error("Problem registering shutdownHook", e);
089:                } catch (InvocationTargetException e) {
090:                    LOG.error("Problem registering shutdownHook", e);
091:                }
092:            }
093:
094:            /**
095:             * Remove all connection pools without delay. Only runs if the
096:             * shutdown hook is {@link org.logicalcobwebs.proxool.ProxoolFacade#isShutdownHookEnabled() enabled}.
097:             * @see ProxoolFacade#removeAllConnectionPools
098:             */
099:            public void run() {
100:                if (ProxoolFacade.isShutdownHookEnabled()) {
101:                    LOG.debug("Running ShutdownHook");
102:                    Thread.currentThread().setName("Shutdown Hook");
103:                    ProxoolFacade.shutdown(0);
104:                } else {
105:                    LOG
106:                            .debug("Skipping ShutdownHook because it's been disabled");
107:                }
108:            }
109:
110:        }
111:
112:        /*
113:         Revision history:
114:         $Log: ShutdownHook.java,v $
115:         Revision 1.13  2006/11/02 10:00:34  billhorsman
116:         Added ProxoolFacade.disableShutdownHook.
117:
118:         Revision 1.12  2006/01/18 14:40:02  billhorsman
119:         Unbundled Jakarta's Commons Logging.
120:
121:         Revision 1.11  2003/12/16 09:09:32  billhorsman
122:         Switched from getCause() to getTargetException() so that we can trap the IllegalStateException in all JDKs.
123:
124:         Revision 1.10  2003/11/16 18:19:14  chr32
125:         Started calling to Exception.getCause() via refletion to maintain compilability with < jdk 1.4 compilers.
126:
127:         Revision 1.9  2003/10/27 12:32:06  billhorsman
128:         Fixed typos and silently ignore IllegalStateException during shutdownHook removal (it's probably because
129:         the JVM is shutting down).
130:
131:         Revision 1.8  2003/09/07 22:05:15  billhorsman
132:         Now uses reflection to add ShutdownHook to Runtime so that it is JDK independent. Using JDK1.2
133:         will disable the shutdownHook and simply log a warning message that Proxool must be shutdown
134:         explicitly.
135:
136:         Revision 1.7  2003/03/03 17:07:58  billhorsman
137:         name thread
138:
139:         Revision 1.6  2003/03/03 11:11:58  billhorsman
140:         fixed licence
141:
142:         Revision 1.5  2003/02/26 11:20:59  billhorsman
143:         removed debug
144:
145:         Revision 1.4  2003/02/10 15:13:57  billhorsman
146:         fixed deprecated call
147:
148:         Revision 1.3  2003/02/06 17:41:05  billhorsman
149:         now uses imported logging
150:
151:         Revision 1.2  2003/02/04 17:19:11  billhorsman
152:         ShutdownHook now initialises
153:
154:         Revision 1.1  2003/02/04 15:04:17  billhorsman
155:         New ShutdownHook
156:
157:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.