1 23 24 package com.sun.enterprise.admin.monitor.stats.spi; 25 import java.lang.management.ManagementFactory ; 26 import java.lang.management.ThreadMXBean ; 27 import javax.management.j2ee.statistics.Statistic ; 28 import javax.management.j2ee.statistics.CountStatistic ; 29 import com.sun.enterprise.admin.monitor.stats.JVMThreadStats; 30 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 31 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 32 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 33 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 34 import com.sun.enterprise.admin.monitor.stats.StringStatistic; 35 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl; 36 import com.sun.enterprise.admin.monitor.stats.StatisticImpl; 37 import com.sun.enterprise.util.i18n.StringManager; 38 39 40 public class JVMThreadStatsImpl implements JVMThreadStats { 41 42 private GenericStatsImpl baseStatsImpl; 43 private static final String STATS_INTERFACE_NAME = 44 "com.sun.enterprise.admin.monitor.stats.JVMThreadStats"; 45 private ThreadMXBean bean; 46 private MutableCountStatistic curThreadCpuTime; 47 private MutableCountStatistic daemonThreadCount; 48 private MutableCountStatistic peakThreadCount; 49 private MutableCountStatistic threadCount; 50 private MutableCountStatistic totalStartedThreadCount; 51 final long initTime; 52 static String DELIMITER = ","; 53 54 55 private static final StringManager localStrMgr = 56 StringManager.getManager(JVMThreadStatsImpl.class); 57 58 59 public JVMThreadStatsImpl() { 60 initTime = System.currentTimeMillis (); 61 try { 62 baseStatsImpl = new GenericStatsImpl(STATS_INTERFACE_NAME, this); 63 } catch(Exception e) { 64 65 } 66 67 bean = ManagementFactory.getThreadMXBean(); 68 initializeStatistics(); 70 } 71 72 public StringStatistic getAllThreadIds() { 73 long[] ids = bean.getAllThreadIds(); 74 String idString = new String (); 75 for(int i = 0; i < ids.length; i++) 76 { 77 idString = idString.concat(String.valueOf(ids[i])); 78 idString = idString.concat(DELIMITER); 79 } 80 81 return new StringStatisticImpl(idString, 82 localStrMgr.getString("monitor.stats.live_threads"), 83 localStrMgr.getString("monitor.stats.string_units"), 84 localStrMgr.getString("monitor.stats.live_threads_desc"), 85 initTime, 86 System.currentTimeMillis()); 87 } 88 89 public CountStatistic getCurrentThreadCPUTime() { 90 curThreadCpuTime.setCount(bean.getCurrentThreadCpuTime()); 91 return (CountStatistic ) curThreadCpuTime.unmodifiableView (); 92 } 93 94 public CountStatistic getDaemonThreadCount() { 95 daemonThreadCount.setCount(bean.getDaemonThreadCount()); 96 return (CountStatistic ) daemonThreadCount.unmodifiableView(); 97 } 98 99 public StringStatistic getMonitorDeadlockedThreads() { 100 long[] ids = bean.findMonitorDeadlockedThreads(); 101 String idString = new String (); 102 if(ids != null) { 103 for(int i = 0; i < ids.length; i++) { 104 idString = idString.concat(String.valueOf(ids[i])); 105 idString = idString.concat(DELIMITER); 106 } 107 } 108 if((ids == null) || (ids.length == 0)) { 109 idString = idString.concat( 110 localStrMgr.getString("monitor.stats.no_thread_deadlock")); 111 } 112 return new StringStatisticImpl(idString, 113 localStrMgr.getString("monitor.stats.dlocked_threads"), 114 localStrMgr.getString("monitor.stats.string_units"), 115 localStrMgr.getString("monitor.stats.dlocked_threads_desc"), 116 initTime, 117 System.currentTimeMillis()); 118 119 } 120 121 public CountStatistic getPeakThreadCount() { 122 peakThreadCount.setCount(bean.getPeakThreadCount()); 123 return (CountStatistic ) peakThreadCount.unmodifiableView(); 124 } 125 126 public CountStatistic getThreadCount() { 127 threadCount.setCount(bean.getThreadCount()); 128 return (CountStatistic ) threadCount.unmodifiableView(); 129 } 130 131 public CountStatistic getTotalStartedThreadCount() { 132 totalStartedThreadCount.setCount(bean.getTotalStartedThreadCount()); 133 return (CountStatistic ) totalStartedThreadCount.unmodifiableView(); 134 } 135 136 137 138 143 public Statistic [] getStatistics() { 144 return baseStatsImpl.getStatistics(); 145 } 146 147 151 public Statistic getStatistic(String str) { 152 return baseStatsImpl.getStatistic(str); 153 } 154 155 160 public String [] getStatisticNames() { 161 return baseStatsImpl.getStatisticNames(); 162 } 163 164 private void initializeStatistics() { 165 166 CountStatistic c = new CountStatisticImpl( 168 localStrMgr.getString("thread_cpu_time"), 169 localStrMgr.getString("monitor.stats.nano_sec_units"), 170 localStrMgr.getString("thread_cpu_time_desc")); 171 curThreadCpuTime = new MutableCountStatisticImpl(c); 172 173 c= new CountStatisticImpl( 175 localStrMgr.getString("monitor.stats.daemon_thread_count"), 176 StatisticImpl.DEFAULT_UNIT, 177 localStrMgr.getString("monitor.stats.daemon_thread_count_desc")); 178 daemonThreadCount = new MutableCountStatisticImpl(c); 179 180 c = new CountStatisticImpl( 182 localStrMgr.getString("monitor.stats.peak_thread_count"), 183 StatisticImpl.DEFAULT_UNIT, 184 localStrMgr.getString("monitor.stats.peak_thread_count_desc")); 185 peakThreadCount = new MutableCountStatisticImpl(c); 186 187 c = new CountStatisticImpl( 189 localStrMgr.getString("monitor.stats.thread_count"), 190 StatisticImpl.DEFAULT_UNIT, 191 localStrMgr.getString("monitor.stats.thread_count_desc")); 192 threadCount = new MutableCountStatisticImpl(c); 193 194 c = new CountStatisticImpl( 196 localStrMgr.getString("monitor.stats.started_thread_count"), 197 StatisticImpl.DEFAULT_UNIT, 198 localStrMgr.getString("monitor.stats.started_thread_count_desc")); 199 totalStartedThreadCount = new MutableCountStatisticImpl(c); 200 } 201 } 202 | Popular Tags |