01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
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 {
24: private static final Logger log = Logging
25: .getLoggerInstance(JDBCProbe.class);
26:
27: private JDBC parent = null;
28: private long checkTime;
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 "
49: + (checkTime / 1000) + " s");
50: // todo: how to stop this thread except through interrupting it?
51: while (true) {
52: try {
53: Thread.sleep(checkTime);
54: } catch (InterruptedException e) {
55: log.debug(Thread.currentThread().getName()
56: + " was interrupted.");
57: break; // likely interrupted due to MMBase going down - break out of loop
58: }
59:
60: try {
61: parent.checkTime();
62: } catch (Exception e) {
63: log.error(e.getMessage());
64: }
65: }
66: }
67: }
|