1 25 26 package org.objectweb.jonas.dbm; 27 import org.objectweb.jonas.common.Log; 28 import org.objectweb.util.monolog.api.Logger; 29 import org.objectweb.util.monolog.api.BasicLevel; 30 31 36 public class PoolKeeper extends Thread { 37 38 41 private Pool pool; 42 43 46 private Logger logger = null; 47 48 51 private long adjustperiod = 15000L; 53 56 private long samplingperiod = 60000L; 58 61 private final long errorperiod = 120000L; 63 67 public PoolKeeper(Pool pool, Logger log) { 68 super("PoolKeeper"); 69 setDaemon(true); 70 this.pool = pool; 71 logger = log; 72 } 73 74 81 public void setSamplingPeriod(int sec) { 82 if (logger.isLoggable(BasicLevel.DEBUG)) { 83 logger.log(BasicLevel.DEBUG, " to " + sec); 84 } 85 samplingperiod = sec * 1000L; 86 } 87 88 91 public void run() { 92 long timeout; 93 long adjusttime = adjustperiod; 94 long samplingtime = samplingperiod; 95 while (true) { 96 timeout = adjusttime; 97 if (samplingtime < timeout) { 98 timeout = samplingtime; 99 } 100 try { 101 sleep(timeout); 102 adjusttime -= timeout; 103 samplingtime -= timeout; 104 if (adjusttime <= 0) { 105 pool.adjust(); 106 adjusttime = adjustperiod; 107 } 108 if (samplingtime <= 0) { 109 pool.sampling(); 110 samplingtime = samplingperiod; 111 } 112 } catch (NullPointerException e) { 113 logger.log(BasicLevel.ERROR, "poolkeeper NPE", e); 114 e.printStackTrace(); 115 adjusttime = errorperiod; 116 samplingtime = errorperiod; 117 } catch (Exception e) { 118 logger.log(BasicLevel.ERROR, "poolkeeper error", e); 119 e.printStackTrace(); 120 adjusttime = errorperiod; 121 samplingtime = errorperiod; 122 } 123 } 124 } 125 } 126 | Popular Tags |