1 22 package org.jboss.monitor; 23 24 import java.io.Serializable ; 25 26 39 public class LockMonitor implements Serializable 40 { 41 43 44 private static final long serialVersionUID = -6710878502772579272L; 45 46 47 private long totalTime; 48 private long numContentions; 49 private long timeouts; 50 private long maxContenders; 51 private long currentContenders; 52 53 54 private transient EntityLockMonitor parent; 55 56 58 61 public LockMonitor(EntityLockMonitor parent) 62 { 63 this.parent = parent; 64 } 65 66 68 public synchronized long getTotalTime() 69 { 70 return totalTime; 71 } 72 73 public synchronized long getNumContentions() 74 { 75 return numContentions; 76 } 77 78 public synchronized long getTimeouts() 79 { 80 return timeouts; 81 } 82 83 public synchronized long getMaxContenders() 84 { 85 return maxContenders; 86 } 87 88 public synchronized long getCurrentContenders() 89 { 90 return currentContenders; 91 } 92 93 95 101 public void contending() 102 { 103 synchronized(this) 104 { 105 ++numContentions; 106 ++currentContenders; 107 108 if (currentContenders > maxContenders) 109 { 110 maxContenders = currentContenders; 111 } 112 } 113 114 if (parent != null) 118 { 119 parent.incrementContenders(); 120 } 121 } 122 123 129 public void finishedContending(long time) 130 { 131 synchronized(this) 132 { 133 totalTime += time; 134 --currentContenders; 135 } 136 137 if (parent != null) 141 { 142 parent.decrementContenders(time); 143 } 144 } 145 146 149 public void increaseTimeouts() 150 { 151 synchronized(this) 152 { 153 ++timeouts; 154 } 155 } 156 157 163 public void reset() 164 { 165 synchronized(this) 166 { 167 timeouts = 0; 168 totalTime = 0; 169 numContentions = 0; 170 maxContenders = currentContenders; 172 } 173 } 174 175 177 public String toString() 178 { 179 StringBuffer sbuf = new StringBuffer (128); 180 181 sbuf.append(super.toString()) 182 .append("[ ") 183 .append("totalTime=").append(getTotalTime()) 184 .append(", numContentions=").append(getNumContentions()) 185 .append(", timeouts=").append(getTimeouts()) 186 .append(", maxContenders=").append(getMaxContenders()) 187 .append(", currentContenders=").append(getCurrentContenders()) 188 .append(" ]"); 189 190 return sbuf.toString(); 191 } 192 } | Popular Tags |