?????????????????

??????????????????????????????product???????????????????????????????????????????product ????copy????????????У??????????????????????????????????????????????????????????????????????????????????????????????????Щ??????????????????????????????????????????????????????????????????????ο???

import org.slf4j.Logger;  
    
  public class TraceUtil {  
      final Logger logger;  
      final long threshold = 1000;  
      private long begin;  
      private long offtime = 0;  
      private String threadInfo;  
      private String targetId;  
    
      public TraceUtil(Logger logger?? Thread thread?? String targetId?? long begin) {  
          this.logger = logger;  
          this.threadInfo = thread.getId() + "-" + thread.toString();  
          this.targetId = targetId;  
          this.begin = begin;  
      }  
    
      public void trace(String targetEvent) {  
          long duration = System.currentTimeMillis() - begin;  
          long increment = duration - offtime;  
          offtime = duration;  
          float percentage = (float) increment / (float) duration * 100;  
          if (duration > threshold && percentage > 20) {  
              logger.error(  
                      "Response time is too large: [{}]?? {}/{} ({})?? {}?? {}"??  
                      new String[] { threadInfo + ""?? increment + ""??  
                              duration + ""?? percentage + "%"?? targetEvent??  
                              targetId });  
          }  
    
      }  
    
  }
 ????????JVM??MXBean???blocked???

??????????JVM????cpu????????????????????????????IO??????????????豸????????п??????????????????????????????????????????????????????????????JVM????monitor API??????

<%@ page import="java.lang.management.*?? java.util.*" %>   
    <%!   
        Map cpuTimes = new HashMap();   
        Map cpuTimeFetch = new HashMap();   
    %>   
       
    <%   
    out.println("Threads Monitoring");   
    long cpus = Runtime.getRuntime().availableProcessors();   
    ThreadMXBean threads = ManagementFactory.getThreadMXBean();   
    threads.setThreadContentionMonitoringEnabled(true);   
    long now = System.currentTimeMillis();   
    ThreadInfo[] t = threads.dumpAllThreads(false?? false);   
    for (int i = 0; i < t.length; i++) {   
        long id = t[i].getThreadId();   
        Long idObj = new Long(id);   
        long current = 0;   
        if (cpuTimes.get(idObj) != null) {   
            long prev = ((Long) cpuTimes.get(idObj)).longValue();   
            current = threads.getThreadCpuTime(t[i].getThreadId());   
            long catchTime = ((Long) cpuTimeFetch.get(idObj)).longValue();   
            double percent = (double)(current - prev) / (double)((now - catchTime) * cpus * 1000);   
            if (percent > 0 && prev > 0) {  
    out.println("<li>" + t[i].getThreadName()+"#"+t[i].getThreadId() + " Time: " + percent + " (" + prev + "?? " + current + ") ");  
    String locked = t[i].getLockInfo()==null?"":t[i].getLockInfo().getClassName();  
    out.println(" Blocked: (" + t[i].getBlockedTime() + "?? " + t[i].getBlockedCount() + "?? " + locked + ")</li>");  
    }  
        }   
        cpuTimes.put(idObj?? new Long(current));     
        cpuTimeFetch.put(idObj?? new Long(now));   
    }   
    %>
 
????????????????????

?????????????????????block???????????????????cpu?????????????????????????IO????????????豸???????????????ü??????????????????????????????synchronizae???????????????????????????jar????????????????????????????£????????????????????????д????????????????????????????????