1 24 25 package org.objectweb.cjdbc.requestplayer; 26 27 import org.objectweb.cjdbc.common.util.Stats; 28 29 35 public class MonitoringThread extends Thread 36 { 37 38 private Stats selectStats = null; 39 40 41 private Stats unknownStats = null; 42 43 44 private Stats updateStats = null; 45 46 47 private Stats insertStats = null; 48 49 50 private Stats deleteStats = null; 51 52 53 private long timeInMs; 55 56 private boolean killed = false; 57 58 64 public MonitoringThread(ClientEmulator father, long timeInMs) 65 { 66 super("MonitoringThread"); 67 68 selectStats = father.getSelectStats(); 70 unknownStats = father.getUnknownStats(); 71 updateStats = father.getUpdateStats(); 72 insertStats = father.getInsertStats(); 73 deleteStats = father.getDeleteStats(); 74 75 this.timeInMs = timeInMs; 76 } 77 78 81 public void run() 82 { 83 int oldStats = 0; 84 int currentStats; 85 for (int i = 0; !killed; i++) 86 { 87 try 88 { 89 Thread.sleep(timeInMs); 90 } 91 catch (InterruptedException e) 92 { 93 System.out.println("Monitoring thread interrupted"); 94 break; 95 } 96 currentStats = selectStats.getCount() + updateStats.getCount() 97 + insertStats.getCount() + deleteStats.getCount() 98 + unknownStats.getCount(); 99 System.out.println("Monitor:" + i + ": " + (currentStats - oldStats)); 100 oldStats = currentStats; 101 } 102 } 103 104 109 public boolean isKilled() 110 { 111 return killed; 112 } 113 114 119 public void setKilled(boolean killed) 120 { 121 this.killed = killed; 122 } 123 } | Popular Tags |