KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > database > JDBCProbe


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.module.database;
11
12 import org.mmbase.module.core.MMBaseContext;
13 import org.mmbase.util.logging.Logger;
14 import org.mmbase.util.logging.Logging;
15
16 /**
17  * JDBCProbe checks all JDBC connection every X seconds to find and
18  * remove bad connections works using a callback into JDBC.
19  *
20  * @version $Id: JDBCProbe.java,v 1.14 2006/02/10 16:03:00 michiel Exp $
21  * @author Daniel Ockeloen
22  */

23 public class JDBCProbe implements Runnable JavaDoc {
24     private static final Logger log = Logging.getLoggerInstance(JDBCProbe.class);
25
26     private JDBC parent = null;
27     private long checkTime;
28
29
30     public JDBCProbe(JDBC parent) {
31         this(parent, 30);
32     }
33
34     public JDBCProbe(JDBC parent, int ct) {
35         this(parent, (long) ct * 1000);
36     }
37
38     public JDBCProbe(JDBC parent, long ct) {
39         this.parent = parent;
40         checkTime = ct;
41         MMBaseContext.startThread(this, "JDBCProbe");
42     }
43
44     /**
45      * admin probe, try's to make a call to all the maintainance calls.
46      */

47     public void run () {
48         log.service("JDBC probe starting with sleep time of " +( checkTime / 1000) + " s");
49         // todo: how to stop this thread except through interrupting it?
50
while (true) {
51             try {
52                 Thread.sleep(checkTime);
53             } catch(InterruptedException JavaDoc e) {
54                 log.debug(Thread.currentThread().getName() +" was interrupted.");
55                 break; // likely interrupted due to MMBase going down - break out of loop
56
}
57
58             try {
59                 parent.checkTime();
60             } catch (Exception JavaDoc e) {
61                 log.error(e.getMessage());
62             }
63         }
64     }
65 }
66
Popular Tags