﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-心有多大，舞台就有多大</title><link>http://www.blogjava.net/yangpingyu/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 12 Apr 2026 06:01:03 GMT</lastBuildDate><pubDate>Sun, 12 Apr 2026 06:01:03 GMT</pubDate><ttl>60</ttl><item><title>perf4j使用四（log4j集成图表查看）</title><link>http://www.blogjava.net/yangpingyu/archive/2012/04/19/375267.html</link><dc:creator>yangpingyu</dc:creator><author>yangpingyu</author><pubDate>Thu, 19 Apr 2012 06:12:00 GMT</pubDate><guid>http://www.blogjava.net/yangpingyu/archive/2012/04/19/375267.html</guid><wfw:comment>http://www.blogjava.net/yangpingyu/comments/375267.html</wfw:comment><comments>http://www.blogjava.net/yangpingyu/archive/2012/04/19/375267.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/yangpingyu/comments/commentRss/375267.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yangpingyu/services/trackbacks/375267.html</trackback:ping><description><![CDATA[&nbsp; 
<div>
<p><span style="font-family: 宋体">在使用二这编文章中提到，可以以汇总形式查看日志，也可以通过图表来查看。</span>Perf4j<span style="font-family: 宋体">跟</span>log4j<span style="font-family: 宋体">集成后，其实也可以以图表的形式来查看性能状况。</span></p>
<p>&nbsp;</p>
<p><span style="font-family: 宋体">我们这篇文章还是使用前一篇文章中提到</span>log4j.xml<span style="font-family: 宋体">的配置，其他都一样，只是在配置中加入了图表的配置：</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&lt;!-- </span><span style="font-family: 宋体; font-size: 10pt; courier: ">生成</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">firstBlock,secondBlock</span><span style="font-family: 宋体; font-size: 10pt; courier: ">的平均值的图表</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt"> --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"graphExecutionTimes"</span></em></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.perf4j.log4j.GraphingStatisticsAppender"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&lt;!-- GraphType:Mean</span><span style="font-family: 宋体; font-size: 10pt; courier: ">（平均值）</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">, <u>Min</u></span><span style="font-family: 宋体; font-size: 10pt; courier: ">（最小值）</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">, Max</span><span style="font-family: 宋体; font-size: 10pt; courier: ">（最大值）</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">, TPS</span><span style="font-family: 宋体; font-size: 10pt; courier: ">（每秒事务数）</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt"> --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"GraphType"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"Mean"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"TagNamesToGraph"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"firstBlock,secondBlock"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender-ref</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">ref</span><span style="color: black">=</span><em><span style="color: #2a00ff">"graphsFileAppender"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&lt;!-- </span><span style="font-family: 宋体; font-size: 10pt; courier: ">生成</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">firstBlock,secondBlock</span><span style="font-family: 宋体; font-size: 10pt; courier: ">的</span><u><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">tps</span></u><span style="font-family: 宋体; font-size: 10pt; courier: ">的图表</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt"> --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"graphExecutionTPS"</span></em></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.perf4j.log4j.GraphingStatisticsAppender"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"GraphType"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"TPS"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"TagNamesToGraph"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"firstBlock,secondBlock"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender-ref</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">ref</span><span style="color: black">=</span><em><span style="color: #2a00ff">"graphsFileAppender"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&lt;!-- </span><span style="font-family: 宋体; font-size: 10pt; courier: ">记录图表生成</span><u><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">url</span></u><span style="font-family: 宋体; font-size: 10pt; courier: ">的</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">log</span><span style="font-family: 宋体; font-size: 10pt; courier: ">文件</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt"> --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"graphsFileAppender"</span></em> <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.apache.log4j.FileAppender"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"File"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"/home/perfGraphs.log"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">layout</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.apache.log4j.PatternLayout"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"ConversionPattern"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"%m%n"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">layout</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left; text-indent: 21pt" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 宋体">另外还需要改一个地方，就是</span>CoalescingStatistics<span style="font-family: 宋体">的配置：</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: silver; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"CoalescingStatistics"</span></em></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.perf4j.log4j.AsyncCoalescingStatisticsAppender"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&lt;!--</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; TimeSlice</span><span style="font-family: 宋体; font-size: 10pt; courier: ">配置多少时间间隔去做一次汇总写入文件中</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</span><span style="font-family: 宋体; font-size: 10pt; courier: ">默认值是</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt"> 30000 <u>ms</u></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"TimeSlice"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"10000"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender-ref</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">ref</span><span style="color: black">=</span><em><span style="color: #2a00ff">"fileAppender"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">appender-ref</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">ref</span><span style="color: black">=</span><em><span style="color: #2a00ff">"graphExecutionTimes"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">appender-ref</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">ref</span><span style="color: black">=</span><em><span style="color: #2a00ff">"graphExecutionTPS"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New';background: silver; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p><span style="font-family: 宋体">黄色那段配置的意思就是把日志写入到图表日志去。</span></p>
<p><span style="font-family: 宋体">运行代码</span>Perf4JAppenderExample<span style="font-family: 宋体">，我们在</span>perfGraphs.log<span style="font-family: 宋体">文件中生成了图表的</span>url<span style="font-family: 宋体">：</span></p>
<p><a href="http://chart.apis.google.com/chart?cht=lxy&amp;chtt=Mean&amp;chs=750x400&amp;chxt=x,x,y&amp;chd=t:0.0,100.0%7C45.2,78.1%7C0.0,100.0%7C98.1,100.0&amp;chco=ff0000,00ff00&amp;chm=d,ff0000,0,-1,5.0%7Cd,00ff00,1,-1,5.0&amp;chdl=firstBlock%7CsecondBlock&amp;chxr=2,0,828.6&amp;chxl=0:%7C13:23:50%7C13:24:00%7C1:%7CTime&amp;chxp=0,0.0,100.0%7C1,50&amp;chg=50.0,10">http://chart.apis.google.com/chart?cht=lxy&amp;chtt=Mean&amp;chs=750x400&amp;chxt=x,x,y&amp;chd=t:0.0,100.0|45.2,78.1|0.0,100.0|98.1,100.0&amp;chco=ff0000,00ff00&amp;chm=d,ff0000,0,-1,5.0|d,00ff00,1,-1,5.0&amp;chdl=firstBlock|secondBlock&amp;chxr=2,0,828.6&amp;chxl=0:|13:23:50|13:24:00|1:|Time&amp;chxp=0,0.0,100.0|1,50&amp;chg=50.0,10</a></p>
<p>&nbsp;</p>
<p><a href="http://chart.apis.google.com/chart?cht=lxy&amp;chtt=TPS&amp;chs=750x400&amp;chxt=x,x,y&amp;chd=t:0.0,100.0%7C100.0,100.0%7C0.0,100.0%7C100.0,100.0&amp;chco=ff0000,00ff00&amp;chm=d,ff0000,0,-1,5.0%7Cd,00ff00,1,-1,5.0&amp;chdl=firstBlock%7CsecondBlock&amp;chxr=2,0,0.5&amp;chxl=0:%7C13:23:50%7C13:24:00%7C1:%7CTime&amp;chxp=0,0.0,100.0%7C1,50&amp;chg=50.0,10">http://chart.apis.google.com/chart?cht=lxy&amp;chtt=TPS&amp;chs=750x400&amp;chxt=x,x,y&amp;chd=t:0.0,100.0|100.0,100.0|0.0,100.0|100.0,100.0&amp;chco=ff0000,00ff00&amp;chm=d,ff0000,0,-1,5.0|d,00ff00,1,-1,5.0&amp;chdl=firstBlock|secondBlock&amp;chxr=2,0,0.5&amp;chxl=0:|13:23:50|13:24:00|1:|Time&amp;chxp=0,0.0,100.0|1,50&amp;chg=50.0,10</a></p>
<p><span style="font-family: 宋体">大家可以把</span>url<span style="font-family: 宋体">放到浏览器访问下。</span></p>
<p>&nbsp;</p>
<p><span style="font-family: 宋体">上面这种方式呢，需要自己登录到服务器上，找到</span>log<span style="font-family: 宋体">文件，在放到浏览器中查看，总的过程还是比较麻烦。如果大家需要监控的工程是一个</span>web<span style="font-family: 宋体">工程的话，那就更方便了，直接配置一个</span>servlet<span style="font-family: 宋体">来查看。</span>Web.xml<span style="font-family: 宋体">的配置如下：</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;!</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">DOCTYPE</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: teal">web-app</span> <span style="color: gray">PUBLIC</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; font-size: 10pt">&nbsp;<span style="color: teal">"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; font-size: 10pt">&nbsp;<span style="color: #3f7f5f">"http://java.sun.com/dtd/web-app_2_3.dtd"</span> <span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">web-app</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">display-name</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">Archetype Created Web Application</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">display-name</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">servlet</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">servlet-name</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">perf4j</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">servlet-name</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">servlet-class</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">org.perf4j.log4j.servlet.GraphingServlet</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">servlet-class</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&lt;!-- graphExecutionTimes</span><span style="font-family: 宋体; font-size: 10pt; courier: ">和</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">graphExecutionTPS</span><span style="font-family: 宋体; font-size: 10pt; courier: ">就是我们在</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">log4j</span><span style="font-family: 宋体; font-size: 10pt; courier: ">中配置的名称</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt"> --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">init-param</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param-name</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">graphNames</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param-name</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param-value</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">graphExecutionTimes,graphExecutionTPS</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param-value</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">init-param</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">servlet</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">servlet-mapping</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">servlet-name</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">perf4j</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">servlet-name</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">url-pattern</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">/perf4j</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">url-pattern</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">servlet-mapping</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">web-app</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p><span style="font-family: 宋体">大家可以打包工程，并放到</span>web<span style="font-family: 宋体">服务器下启动，然后访问下</span>/perf4j<span style="font-family: 宋体">这个</span>uri<span style="font-family: 宋体">。</span></p>
<p>Maven<span style="font-family: 宋体">有一个</span>jetty<span style="font-family: 宋体">插件，可以方便启动</span>web<span style="font-family: 宋体">工程，只要大家在</span>pom.xml<span style="font-family: 宋体">文件中加入如下配置：</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">plugins</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&lt;!-- <u>jetty</u></span><span style="font-family: 宋体; font-size: 10pt; courier: ">插件</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">, </span><span style="font-family: 宋体; font-size: 10pt; courier: ">设定端口与</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">context path--&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">plugin</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">groupId</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">org.mortbay.jetty</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">groupId</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">artifactId</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span><u><span style="font-family: 'Courier New'; color: black; font-size: 10pt">jetty</span></u><span style="font-family: 'Courier New'; color: black; font-size: 10pt">-<u>maven</u>-<u>plugin</u></span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">artifactId</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">plugin</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">plugins</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p><span style="font-family: 宋体">在控制台中输入：</span>mvn jetty:run<span style="font-family: 宋体">，即可。省去了打包发布，很省心喔。</span></p>
<p><span style="font-family: 宋体">第一次用</span><a href="http://localhost:8080/perf4j">http://localhost:8080/perf4j</a><span style="font-family: 宋体">访问查看图表的时候没有生成任何东西，那是因为内存中没有收集到最新的性能数据。所以我在</span>index.jsp<span style="font-family: 宋体">里调用下以便产生性能数据。然后重新访问，这个时候就有图表生成了。</span></p></div><br /><a href="/Files/yangpingyu/baowu.rar">下载工程<br /></a><img src ="http://www.blogjava.net/yangpingyu/aggbug/375267.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yangpingyu/" target="_blank">yangpingyu</a> 2012-04-19 14:12 <a href="http://www.blogjava.net/yangpingyu/archive/2012/04/19/375267.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>perf4j使用三（log4j集成）</title><link>http://www.blogjava.net/yangpingyu/archive/2012/04/16/374725.html</link><dc:creator>yangpingyu</dc:creator><author>yangpingyu</author><pubDate>Mon, 16 Apr 2012 05:59:00 GMT</pubDate><guid>http://www.blogjava.net/yangpingyu/archive/2012/04/16/374725.html</guid><wfw:comment>http://www.blogjava.net/yangpingyu/comments/374725.html</wfw:comment><comments>http://www.blogjava.net/yangpingyu/archive/2012/04/16/374725.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yangpingyu/comments/commentRss/374725.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yangpingyu/services/trackbacks/374725.html</trackback:ping><description><![CDATA[<div>
<p><span style="font-family: 宋体">Perf4j</span><span style="font-family: 宋体">最主要的一个好处就是可以跟log4j或者logback来性能分析和监控线上运行的程序。集成的方式主要是：自定义log4j的appenders通过标准的配置加入到log4j中去（后面会有配置的例子）。有一个要注意的地方就是需要使用log4j的1.2.14版本或者更高版本。由于我一般都是使用log4j，所以对于logback的集成我就不描述了，我觉得应该差不多的。</span></p>
<p>&nbsp;</p>
<p><span style="font-family: 宋体">Perf4j</span><span style="font-family: 宋体">最重要的appender就是</span><a href="http://perf4j.codehaus.org/apidocs/org/perf4j/log4j/AsyncCoalescingStatisticsAppender.html"><span style="font-family: 宋体">AsyncCoalescingStatisticsAppender</span></a><span style="font-family: 宋体">，它会把一段时间内StopWatch的信息汇总到一个独立的GroupedTimingStatistics日志信息，然后把这个独立的信息传给下游的appenders，比如fileappenders，这样就可以写到文件中去了。也可以传给per4j的其他自定义appenders。</span></p>
<p>&nbsp;</p>
<p><span style="font-family: 宋体">接下来我们看一个log4j.xml的例子，有一个限制，如果要使用AsyncCoalescingStatisticsAppender就只能使用xml文件而不能使用properties文件。</span></p>
<p>&nbsp;</p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;?</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">xml</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">version</span><span style="color: black">=</span><em><span style="color: #2a00ff">"1.0"</span></em> <span style="color: #7f007f">encoding</span><span style="color: black">=</span><em><span style="color: #2a00ff">"UTF-8"</span></em> <span style="color: teal">?&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;!</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">DOCTYPE</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: teal">log4j:configuration</span> <span style="color: gray">SYSTEM</span> <span style="color: #3f7f5f">"log4j.dtd"</span><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">log4j:configuration</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">debug</span><span style="color: black">=</span><em><span style="color: #2a00ff">"false"</span></em> <span style="color: #7f007f">xmlns:log4j</span><span style="color: black">=</span><em><span style="color: #2a00ff">"http://jakarta.apache.org/log4j/"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&lt;!--</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 10pt; courier: ">配置控制台输出</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp; --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"console"</span></em> <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.apache.log4j.ConsoleAppender"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">layout</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.apache.log4j.PatternLayout"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"ConversionPattern"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"%-5p %c{1} - %m%n"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">layout</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span> </p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&lt;!-- Perf4J appenders --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&lt;!--</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>AsyncCoalescingStatisticsAppender</span><span style="font-family: 宋体; font-size: 10pt; courier: ">收集</span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">StopWatch</span><span style="font-family: 宋体; font-size: 10pt; courier: ">的日志信息并传送到下游的文件</span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">appenders</span><span style="font-family: 宋体; font-size: 10pt; courier: ">。</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp; --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"CoalescingStatistics"</span></em></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.perf4j.log4j.AsyncCoalescingStatisticsAppender"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&lt;!--</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; TimeSlice</span><span style="font-family: 宋体; font-size: 10pt; courier: ">配置多少时间间隔去做一次汇总写入文件中</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</span><span style="font-family: 宋体; font-size: 10pt; courier: ">默认值是</span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt"> 30000 <u>ms</u></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"TimeSlice"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"10000"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">appender-ref</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">ref</span><span style="color: black">=</span><em><span style="color: #2a00ff">"fileAppender"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&lt;!-- </span><span style="font-family: 宋体; font-size: 10pt; courier: ">把汇总的</span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">perf4j</span><span style="font-family: 宋体; font-size: 10pt; courier: ">的日志信息写到</span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">perfStats.log</span><span style="font-family: 宋体; font-size: 10pt; courier: ">文件中去</span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt"> --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"fileAppender"</span></em> <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.apache.log4j.FileAppender"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"File"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"/home/perfStats.log"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">layout</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.apache.log4j.PatternLayout"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"ConversionPattern"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"%m%n"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">layout</span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&lt;!-- Loggers --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&lt;!--&nbsp;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 宋体; font-size: 10pt; courier: ">配置</span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">perf4j logger</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Additivity</span><span style="font-family: 宋体; font-size: 10pt; courier: ">设置成</span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">false</span><span style="font-family: 宋体; font-size: 10pt; courier: ">主要因为是不想让代码运行时间的日志输出给上游</span><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">appenders</span><span style="font-family: 宋体; font-size: 10pt; courier: ">，即不要在控制台输出。</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp; --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">logger</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.perf4j.TimingLogger"</span></em> <span style="color: #7f007f">additivity</span><span style="color: black">=</span><em><span style="color: #2a00ff">"false"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">level</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"INFO"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">appender-ref</span><span style="font-family: 'Courier New';background: yellow; font-size: 10pt"> <span style="color: #7f007f">ref</span><span style="color: black">=</span><em><span style="color: #2a00ff">"CoalescingStatistics"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New';background: yellow; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New';background: yellow; color: #3f7f7f; font-size: 10pt">logger</span><span style="font-family: 'Courier New';background: yellow; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&lt;!--&nbsp;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Root logger</span><span style="font-family: 宋体; font-size: 10pt; courier: ">打印所有日志，但不包含</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">perf4j</span><span style="font-family: 宋体; font-size: 10pt; courier: ">的信息。原因是在</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">TimingLogger</span><span style="font-family: 宋体; font-size: 10pt; courier: ">配置中设置了</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">additivity</span><span style="font-family: 宋体; font-size: 10pt; courier: ">为</span><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">false</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: #3f5fbf; font-size: 10pt">&nbsp;&nbsp;&nbsp; --&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">root</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">level</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"INFO"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender-ref</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">ref</span><span style="color: black">=</span><em><span style="color: #2a00ff">"console"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">root</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">log4j:configuration</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="font-family: 宋体">黄色背景是perf4j的配置信息。其他都是log4j的基本配置。下面是测试perf4j与log4j集成的代码。</span></p>
<p style="text-align: left" align="left"><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">package</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt"> com.baowu.perf4j;</span></p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">import</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt"> org.apache.log4j.Logger;</span></p>
<p style="text-align: left" align="left"><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">import</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt"> org.perf4j.StopWatch;</span></p>
<p style="text-align: left" align="left"><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">import</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt"> org.perf4j.log4j.Log4JStopWatch;</span></p>
<p style="text-align: left" align="left">&nbsp;</p>
<p style="text-align: left" align="left"><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">public</span></strong> <strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">class</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt"> Perf4JAppenderExample {</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">public</span></strong> <strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">static</span></strong> <strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">void</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt"> main (String[] args) </span><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">throws</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt"> Exception {</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Logger rootLogger = Logger.<em>getRootLogger</em>();</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">for</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt"> (</span><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">int</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt"> i = 0; i &lt; 10; i++) {</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f7f5f; font-size: 10pt">// Log4JStopWatch</span><span style="font-family: 宋体; font-size: 10pt; courier: ">默认使用</span><span style="font-family: 'Courier New'; color: #3f7f5f; font-size: 10pt">org.perf4j.TimingLogger</span><span style="font-family: 宋体; font-size: 10pt; courier: ">这个类</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StopWatch stopWatch = </span><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">new</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt"> Log4JStopWatch();</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f7f5f; font-size: 10pt">//</span><span style="font-family: 宋体; font-size: 10pt; courier: ">模拟代码运行时间</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.<em>sleep</em>((</span><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">long</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt">) (Math.<em>random</em>() * 1000L));</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: #3f7f5f; font-size: 10pt">//</span><span style="font-family: 宋体; font-size: 10pt; courier: ">打印到控制台</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rootLogger.info(</span><span style="font-family: 'Courier New'; color: #2a00ff; font-size: 10pt">"Normal logging messages only go to the console"</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">);</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stopWatch.lap(</span><span style="font-family: 'Courier New'; color: #2a00ff; font-size: 10pt">"firstBlock"</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">);</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.<em>sleep</em>((</span><strong><span style="font-family: 'Courier New'; color: #7f0055; font-size: 10pt">long</span></strong><span style="font-family: 'Courier New'; color: black; font-size: 10pt">) (Math.<em>random</em>() * 2000L));</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stopWatch.stop(</span><span style="font-family: 'Courier New'; color: #2a00ff; font-size: 10pt">"secondBlock"</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">);</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="font-family: 'Courier New'; color: black; font-size: 10pt">}</span></p>
<p>&nbsp;</p>
<p><span style="font-family: 宋体; font-size: 10pt; courier: ">运行代码。</span></p>
<p><span style="font-family: 宋体; font-size: 10pt; courier: ">控制台输出：</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">INFO&nbsp;root - Normal logging messages only go to the console</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">INFO&nbsp;root - Normal logging messages only go to the console</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">INFO&nbsp;root - Normal logging messages only go to the console</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">INFO&nbsp;root - Normal logging messages only go to the console</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">INFO&nbsp;root - Normal logging messages only go to the console</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">INFO&nbsp;root - Normal logging messages only go to the console</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">INFO&nbsp;root - Normal logging messages only go to the console</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">INFO&nbsp;root - Normal logging messages only go to the console</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">INFO&nbsp;root - Normal logging messages only go to the console</span></p>
<p><span style="font-family: 'Courier New'; color: black; font-size: 10pt">INFO&nbsp;root - Normal logging messages only go to the console</span></p>
<p>&nbsp;</p>
<p><span style="font-family: 宋体; font-size: 10pt; courier: ">文件输出：</span></p>
<p><span style="font-family: 'Courier New'; color: black; font-size: 10pt"><img border="0" alt="" src="http://www.blogjava.net/images/blogjava_net/yangpingyu/perf4j3-1.jpg" width="558" height="184" /><br /></span></p>
<p>&nbsp;</p>
<p><span style="font-family: 宋体; font-size: 10pt; courier: ">输出格式也可以改成</span><span style="font-family: 'Courier New'; color: black; font-size: 10pt">CSV</span><span style="font-family: 宋体; font-size: 10pt; courier: ">格式。配置：</span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"fileAppender"</span></em> <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"org.apache.log4j.FileAppender"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"File"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"/home/perfStats.log"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">layout</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">class</span><span style="color: black">=</span><em><span style="color: #2a00ff">"</span><strong><span style="color: red">org.apache.log4j.PatternLayout</span></strong><span style="color: #2a00ff">"</span></em><span style="color: teal">&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">param</span><span style="font-family: 'Courier New'; font-size: 10pt"> <span style="color: #7f007f">name</span><span style="color: black">=</span><em><span style="color: #2a00ff">"ConversionPattern"</span></em> <span style="color: #7f007f">value</span><span style="color: black">=</span><em><span style="color: #2a00ff">"%m%n"</span></em><span style="color: teal">/&gt;</span></span></p>
<p style="text-align: left" align="left"><span style="font-family: 'Courier New'; color: black; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">layout</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left; text-indent: 21pt" align="left"><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&lt;/</span><span style="font-family: 'Courier New'; color: #3f7f7f; font-size: 10pt">appender</span><span style="font-family: 'Courier New'; color: teal; font-size: 10pt">&gt;</span></p>
<p style="text-align: left; text-indent: 21pt" align="left"><strong><em><span style="font-family: 'Courier New'; color: red; font-size: 10pt">org.apache.log4j.PatternLayout</span></em></strong><strong><em><span style="font-family: 宋体; font-size: 10pt; courier: ">改成</span></em></strong><strong><em><span style="font-family: 'Courier New'; color: red; font-size: 10pt">org.perf4j.log4j.StatisticsCsvLayout</span></em></strong><strong><em><span style="font-family: 宋体; font-size: 10pt; courier: ">即可。</span></em></strong></p>
<p style="text-align: left; text-indent: 21pt" align="left"><strong><em><span style="font-family: 宋体; font-size: 10pt; courier: ">具体的参数请查看</span></em></strong><strong><em><span style="font-family: 'Courier New'; color: red; font-size: 10pt">api</span></em></strong><strong><em><span style="font-family: 宋体; font-size: 10pt; courier: ">。<br /><strong><em><font size="2"><a href="/Files/yangpingyu/baowu.rar"><strong><em><font size="2">下载工程</font></em></strong></a></font></em></strong><br /><br /><br /></span></em></strong></p></div><img src ="http://www.blogjava.net/yangpingyu/aggbug/374725.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yangpingyu/" target="_blank">yangpingyu</a> 2012-04-16 13:59 <a href="http://www.blogjava.net/yangpingyu/archive/2012/04/16/374725.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>perf4j使用二</title><link>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374676.html</link><dc:creator>yangpingyu</dc:creator><author>yangpingyu</author><pubDate>Sun, 15 Apr 2012 11:35:00 GMT</pubDate><guid>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374676.html</guid><wfw:comment>http://www.blogjava.net/yangpingyu/comments/374676.html</wfw:comment><comments>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374676.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yangpingyu/comments/commentRss/374676.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yangpingyu/services/trackbacks/374676.html</trackback:ping><description><![CDATA[<div>  <p><a href="../archive/2012/04/15/374217.html">Perf4j<span style="font-family:宋体;"><span>使用一</span></span></a><span style="font-family:宋体;">主要演示了性能监控的日志直接打印在标准输出流。那么使用二呢则主要来演示怎么来分析打印出来的日志文件。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">由于我们还没有跟</span>log4j<span style="font-family:宋体;">集成，日志文件打印在标准输出流，我们需要把标准输出流重定向到</span>times.log<span style="font-family:宋体;">文件中。重定向有两种方式：直接</span>copy<span style="font-family:宋体;">到文件中，或者在</span>eclipse<span style="font-family:宋体;">里指定下输出文件。我主要是用</span>eclipse<span style="font-family:宋体;">指定输出文件。</span></p>  <p style="text-align:left;" align="left"><span style="font-size:12.0pt;font-family:宋体;"><img src="http://www.blogjava.net/images/blogjava_net/yangpingyu/perf4j2-1.jpg" alt="" width="294" border="0" height="164" /></span></p>  <p>&nbsp;</p>  <p style="text-align:left;" align="left"><span style="font-size:12.0pt;font-family:宋体;"><img src="http://www.blogjava.net/images/blogjava_net/yangpingyu/perf4j2-2.jpg" alt="" width="662" border="0" height="496" /></span></p>  <p style="text-align:left;" align="left"><span style="font-size:12.0pt;font-family:宋体;"><img src="http://www.blogjava.net/images/blogjava_net/yangpingyu/perf4j2-3.jpg" alt="" width="661" border="0" height="454" /></span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">然后运行代码（</span><a href="../archive/2012/04/15/374217.html">Perf4j<span style="font-family:宋体;"><span>使用一</span></span></a><span style="font-family:宋体;">的</span>Example.java<span style="font-family:宋体;">），控制台会在第一句话中打出</span>[Console output redirected to file:E:\yangpingyu\work\times.log]<span style="font-family:宋体;">，这样运行的结果会同时打印在文件中和标准输出中。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">有了</span>times.log<span style="font-family:宋体;">，我们就可以对日志文件进行分析，以找出有问题的代码。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">分析日志命令：</span></p>  <p><span>E:\yangpingyu\work&gt;java -jar perf4j-0.9.16.jar times.log</span></p>  <p style="text-align:left;" align="left"><span style="font-size:12.0pt;font-family:宋体;"><img src="http://www.blogjava.net/images/blogjava_net/yangpingyu/perf4j2-5.jpg" alt="" width="874" border="0" height="457" /></span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">以</span>csv<span style="font-family:宋体;">的格式来查看结果，命令如下：</span></p>  <p style="text-align:left;" align="left"><span style="font-size:12.0pt;font-family:宋体;">java -jar perf4j-0.9.16.jar -f csv times.log</span></p>  <p style="text-align:left;" align="left"><span style="font-size:12.0pt;font-family:宋体;"><img src="http://www.blogjava.net/images/blogjava_net/yangpingyu/perf4j2-6.jpg" alt="" width="867" border="0" height="331" /></span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">以上都是以文本的格式进行输出，但文本没有图表更具有表达力。所以把结果以图表形式输出是必不可少，幸好</span>perf4j<span style="font-family:宋体;">也支持，命令如下：</span></p>  <pre>java -jar perf4j-0.9.16.jar --graph perfGraphs.html times.log</pre>  <p><span style="font-family:宋体;">执行命令后，在控制台输出相应的统计信息，相应的在磁盘上也生成了一个</span>html<span style="font-family:宋体;">，</span>html<span style="font-family:宋体;">里包含平均值图表和</span>tps<span style="font-family:宋体;">图表。</span></p>  <p>&lt;html&gt;</p>  <p><span>&lt;head&gt;&lt;title&gt;Perf4J Performance Graphs&lt;/title&gt;&lt;/head&gt;</span></p>  <p>&lt;body&gt;</p>  <p><span>&lt;br/&gt;&lt;br/&gt;&lt;img src="http://chart.apis.google.com/chart?cht=lxy&amp;chtt=Mean&amp;chs=750x400&amp;chxt=x,x,y&amp;chd=t:0.0,50.0,100.0|56.3,60.1,6.0|0.0,50.0|88.5,94.5|50.0,100.0|43.2,7.2|0.0,50.0,100.0|71.8,57.4,8.0|0.0,50.0,100.0|100.0,61.2,59.6|0.0,50.0,100.0|63.9,62.0,18.7|0.0,50.0,100.0|34.4,72.1,30.1&amp;chco=ff0000,00ff00,0000ff,00ffff,ff00ff,ffff00,000000&amp;chm=d,ff0000,0,-1,5.0|d,00ff00,1,-1,5.0|d,0000ff,2,-1,5.0|d,00ffff,3,-1,5.0|d,ff00ff,4,-1,5.0|d,ffff00,5,-1,5.0|d,000000,6,-1,5.0&amp;chdl=codeBlock1|codeBlock2.failure|codeBlock2.success|codeBlock3|codeBlock4|codeBlock5|codeBlock6&amp;chxr=2,0,748.5&amp;chxl=0:|18:12:00|18:12:30|18:13:00|1:|Time&amp;chxp=0,0.0,50.0,100.0|1,50&amp;chg=50.0,10"/&gt;</span></p>  <p><span>&lt;br/&gt;&lt;br/&gt;&lt;img src="http://chart.apis.google.com/chart?cht=lxy&amp;chtt=TPS&amp;chs=750x400&amp;chxt=x,x,y&amp;chd=t:0.0,50.0,100.0|36.4,90.9,9.1|0.0,50.0|27.3,63.6|50.0,100.0|36.4,9.1|0.0,50.0,100.0|36.4,90.9,9.1|0.0,50.0,100.0|36.4,90.9,9.1|0.0,50.0,100.0|36.4,90.9,9.1|0.0,50.0,100.0|27.3,100.0,9.1&amp;chco=ff0000,00ff00,0000ff,00ffff,ff00ff,ffff00,000000&amp;chm=d,ff0000,0,-1,5.0|d,00ff00,1,-1,5.0|d,0000ff,2,-1,5.0|d,00ffff,3,-1,5.0|d,ff00ff,4,-1,5.0|d,ffff00,5,-1,5.0|d,000000,6,-1,5.0&amp;chdl=codeBlock1|codeBlock2.failure|codeBlock2.success|codeBlock3|codeBlock4|codeBlock5|codeBlock6&amp;chxr=2,0,0.4&amp;chxl=0:|18:12:00|18:12:30|18:13:00|1:|Time&amp;chxp=0,0.0,50.0,100.0|1,50&amp;chg=50.0,10"/&gt;</span></p>  <p>&lt;/body&gt;&lt;/html&gt;</p>  <p><span style="font-family:宋体;">以上是</span>html<span style="font-family:宋体;">的内容，里面最重要的信息就是两个</span>img<span style="font-family:宋体;">标签，里面具体的图片是</span>google chart api<span style="font-family:宋体;">生成。可以打开</span>html<span style="font-family:宋体;">直接查看图表。</span></p>  <p><img src="http://www.blogjava.net/images/blogjava_net/yangpingyu/perf4j2-7.png" alt="" width="750" border="0" height="400" /></p>  <p><img src="http://www.blogjava.net/images/blogjava_net/yangpingyu/perf4j2-9.png" alt="" width="750" border="0" height="400" /></p>  <p><span style="font-family:宋体;">如果想要看更详细的参数，可以使用</span>&#8212;help<span style="font-family:宋体;">来查看。</span>java -jar perf4j-0.9.16.jar &#8211;help<span style="font-family: 宋体;">。</span></p>  </div> <img src ="http://www.blogjava.net/yangpingyu/aggbug/374676.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yangpingyu/" target="_blank">yangpingyu</a> 2012-04-15 19:35 <a href="http://www.blogjava.net/yangpingyu/archive/2012/04/15/374676.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>小工具</title><link>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374599.html</link><dc:creator>yangpingyu</dc:creator><author>yangpingyu</author><pubDate>Sun, 15 Apr 2012 08:46:00 GMT</pubDate><guid>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374599.html</guid><wfw:comment>http://www.blogjava.net/yangpingyu/comments/374599.html</wfw:comment><comments>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374599.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yangpingyu/comments/commentRss/374599.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yangpingyu/services/trackbacks/374599.html</trackback:ping><description><![CDATA[本文主要记录下自己在日常工作中感觉比较好用的一些小工具。目前只有几个，不过遇到好的会不断更新上来。<br /><br /><a href="http://www.cnblogs.com/1-2-3/archive/2008/05/05/emeditor-introduction.html">EmEditor</a>：文本编辑器。<br />onenote：主要用来记录工作列表和一些计划等。<br />google chart api：可以用来制作图表，很方便。性能测试的结果数据做对比图。<br />smartArt：也是图表制作工具，已经集成到2007office中了。<br />awk:linux文本处理工具。类似于脚本。牛逼的程序员应该要掌握的一个工具。<br /><div><br />add by 2012-06-19<br /><div>http://cn.edrawsoft.com/download.php ：画图很漂亮的工具。</div></div><br /><br />待更新。。。<br /><img src ="http://www.blogjava.net/yangpingyu/aggbug/374599.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yangpingyu/" target="_blank">yangpingyu</a> 2012-04-15 16:46 <a href="http://www.blogjava.net/yangpingyu/archive/2012/04/15/374599.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>perf4j使用一</title><link>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374217.html</link><dc:creator>yangpingyu</dc:creator><author>yangpingyu</author><pubDate>Sun, 15 Apr 2012 02:44:00 GMT</pubDate><guid>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374217.html</guid><wfw:comment>http://www.blogjava.net/yangpingyu/comments/374217.html</wfw:comment><comments>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374217.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yangpingyu/comments/commentRss/374217.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yangpingyu/services/trackbacks/374217.html</trackback:ping><description><![CDATA[<div>  <p><span style="font-family: 宋体;">如果大家使用的是</span>maven<span style="font-family: 宋体;">工程，那么现在</span>pom<span style="font-family: 宋体;">文件中加入</span>perf4j<span style="font-family: 宋体;">的依赖。</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">dependency</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p style="text-align: left; text-indent: 21pt;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">groupId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">org.perf4j</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">groupId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p style="text-align: left; text-indent: 21pt;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">artifactId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">perf4j</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">artifactId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p style="text-align: left; text-indent: 21pt;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">version</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">0.9.16</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">version</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p style="text-align: left; text-indent: 21pt;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">scope</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">compile</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">scope</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">dependency</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p><span style="font-family: 宋体;">如果用的是普通工程，那么直接下载</span>jar<span style="font-family: 宋体;">包放入</span>lib<span style="font-family: 宋体;">目录下即可。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体;">例子：</span></p>  <p align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">package</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> com.baowu.per4j;</span></p>  <p align="left">&nbsp;</p>  <p align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">import</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> org.perf4j.LoggingStopWatch;</span></p>  <p align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">import</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> org.perf4j.StopWatch;</span></p>  <p align="left">&nbsp;</p>  <p align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">public</span></strong> <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">class</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> Example1 {</span></p>  <p align="left">&nbsp;</p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">public</span></strong> <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">static</span></strong> <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">void</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> main(String[] args) </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">throws</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> InterruptedException{</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>method1</em>();</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>method2</em>();</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>method3</em>();</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; }</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">/**</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&nbsp;&nbsp;&nbsp; &nbsp;* </span><span style="font-size: 10pt; font-family: 宋体; color: #3f5fbf;">监控一处代码示例</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&nbsp;&nbsp;&nbsp; &nbsp;* </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f9fbf;">@throws</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;"> InterruptedException</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&nbsp;&nbsp;&nbsp; &nbsp;*/</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">private</span></strong> <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">static</span></strong> <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">void</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> method1() </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">throws</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> InterruptedException{</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">//</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">创建一个监控对象，这里使用</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">LoggingStopWatch</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">，它是把结果直接输出到控制台。我们也可以</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">//</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">使用</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">StopWatch</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">的其他子类，比如：</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">Log4JStopWatch</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">，</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">CommonsLogStopWatch</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">。不过这些子类需</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">//</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">要工程使用日志框架</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StopWatch stopWatch = </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">new</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> <u>LoggingStopWatch</u>(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"codeBlock1"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>  <p align="left">&nbsp;</p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">//</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">这里就是一些需要监控的代码，我们命名为</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">codeBlock1</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">//</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">使用线程休眠是为了模拟代码执行时间</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.<em>sleep</em>((</span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">long</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">)(Math.<em>random</em>() * 1000L));</span></p>  <p align="left">&nbsp;</p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">//</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">停止计算代码性能</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stopWatch.stop();</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; }</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">/**</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&nbsp;&nbsp;&nbsp; &nbsp;* </span><span style="font-size: 10pt; font-family: 宋体; color: #3f5fbf;">一个方法多出代码监控</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&nbsp;&nbsp;&nbsp; &nbsp;* </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f9fbf;">@throws</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;"> InterruptedException</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&nbsp;&nbsp;&nbsp; &nbsp;*/</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">private</span></strong> <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">static</span></strong> <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">void</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> method2() </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">throws</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> InterruptedException{</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StopWatch stopWatch = </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">new</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> LoggingStopWatch();</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.<em>sleep</em>((</span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">long</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">)(Math.<em>random</em>() * 1000L));</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stopWatch.lap(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"codeBlock3"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.<em>sleep</em>((</span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">long</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">)(Math.<em>random</em>() * 1000L));</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stopWatch.lap(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"codeBlock4"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.<em>sleep</em>((</span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">long</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">)(Math.<em>random</em>() * 1000L));</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stopWatch.lap(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"codeBlock5"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.<em>sleep</em>((</span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">long</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">)(Math.<em>random</em>() * 1000L));</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stopWatch.stop(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"codeBlock6"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; }</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">/**</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&nbsp;&nbsp;&nbsp; &nbsp;* stop</span><span style="font-size: 10pt; font-family: 宋体; color: #3f5fbf;">方法可以加入一些说明信息</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&nbsp;&nbsp;&nbsp; &nbsp;*/</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">private</span></strong> <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">static</span></strong> <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">void</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> method3(){</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StopWatch stopWatch = </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">new</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> LoggingStopWatch();</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">try</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> {</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">// the code block being timed - this is just a dummy example</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">long</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> sleepTime = (</span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">long</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">)(Math.<em>random</em>() * 1000L);</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Thread.<em>sleep</em>(sleepTime);</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">if</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> (sleepTime &gt; 500L) {</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">throw</span></strong> <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">new</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> Exception(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"Throwing exception"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; stopWatch.stop(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"codeBlock2.success"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">, </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"Sleep time was &lt; 500 ms"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">catch</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> (Exception e) {</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; stopWatch.stop(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"codeBlock2.failure"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">, </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"Exception was: "</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> + e);</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; }</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">}</span></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体;">运行结果：</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: red;">start[1334457619937] time[355] tag[codeBlock1]</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: red;">start[1334457620296] time[152] tag[codeBlock3]</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: red;">start[1334457620453] time[138] tag[codeBlock4]</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: red;">start[1334457620593] time[598] tag[codeBlock5]</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: red;">start[1334457621187] time[700] tag[codeBlock6]</span></p>  <p><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: red;">start[1334457621890] time[619] tag[codeBlock2.failure] </span><u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">message[Exception</span></u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: red;"> was: </span><u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">java.lang.Exception</span></u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: red;">: Throwing exception]</span></p>  </div> <img src ="http://www.blogjava.net/yangpingyu/aggbug/374217.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yangpingyu/" target="_blank">yangpingyu</a> 2012-04-15 10:44 <a href="http://www.blogjava.net/yangpingyu/archive/2012/04/15/374217.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Perf4j简介</title><link>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374215.html</link><dc:creator>yangpingyu</dc:creator><author>yangpingyu</author><pubDate>Sun, 15 Apr 2012 02:15:00 GMT</pubDate><guid>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374215.html</guid><wfw:comment>http://www.blogjava.net/yangpingyu/comments/374215.html</wfw:comment><comments>http://www.blogjava.net/yangpingyu/archive/2012/04/15/374215.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yangpingyu/comments/commentRss/374215.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yangpingyu/services/trackbacks/374215.html</trackback:ping><description><![CDATA[<div>      <p><span style="font-family: 宋体;"></span>Perf4j<span style="font-family: 宋体;">主要的用途是计量代码性能和分析性能数据。</span></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体;">为什么要使用这个工具呢？我们可以联想下最早期</span>java<span style="font-family: 宋体;">开发者调试代码使用的方式，以前没有日志框架，那</span>java<span style="font-family: 宋体;">开发就使用</span>System.out.println()<span style="font-family: 宋体;">来输出自己想查看的变量。但是这样项目上线的话，就要去掉这些打印语句以减少性能影响。那万一在线上出问题了，调试哪里出问题就很麻烦，因为没有输出的日志可查。所以后来有人开发了日志框架，通过日志级别控制日志的输出。</span></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体;">类似的，如果没有</span>perf4j<span style="font-family: 宋体;">，我们在查看代码运行时间的话可以用以下代码来实现：</span></p>  <p>long start = System.currentTimeMillis();</p>  <p>// execute the block of code to be timed</p>  <p><span>System.out.println("ms for block n was: " + (System.currentTimeMillis() - start));</span></p>  <p><span style="font-family: 宋体;">这种方式有几个缺点：</span></p>  <p style="margin-left: 18pt; text-indent: -18pt;"><span>1、&nbsp;</span><span style="font-family: 宋体;">这种方式输出内容比较单一，就是代码总的运行时间。但是我们代码需要查看的性能指标有更多，比如总的平均值，最小值，最大值，</span>tps<span style="font-family: 宋体;">等等。</span></p>  <p style="margin-left: 18pt; text-indent: -18pt;"><span>2、&nbsp;</span><span style="font-family: 宋体;">也许我们的代码在线上运行，我们想把这些值通过图表的形式展示出来。或者把这些内容通过</span>jmx<span style="font-family: 宋体;">输出。</span></p>  <p style="margin-left: 18pt; text-indent: -18pt;"><span>3、&nbsp;</span><span style="font-family: 宋体;">另外，我们可能把</span>perf4j<span style="font-family: 宋体;">跟</span>log4j<span style="font-family: 宋体;">，</span>slf4j<span style="font-family: 宋体;">等日志框架和日志门面系统整合起来。</span></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体;">基于以上这些问题，所以开源社区就出现了</span>perf4j<span style="font-family: 宋体;">（人多力量大，社区的力量就是强大）。</span></p>  <p>Perf4j<span style="font-family: 宋体;">一些特性：</span></p>  <p style="margin-left: 21pt; text-indent: -21pt;"><span style="font-family: Wingdings;">l&nbsp;</span><span style="font-family: 宋体;">简单的停止查看机制来计算语句时间消耗输出。</span></p>  <p style="margin-left: 21pt; text-indent: -21pt;"><span style="font-family: Wingdings;">l&nbsp;</span><span style="font-family: 宋体;">命令行解析</span>log<span style="font-family: 宋体;">文件产生汇总数据和图表。</span></p>  <p style="margin-left: 21pt; text-indent: -21pt;"><span style="font-family: Wingdings;">l&nbsp;</span><span style="font-family: 宋体;">简单的集成日志框架和门面框架。</span></p>  <p style="margin-left: 21pt; text-indent: -21pt;"><span style="font-family: Wingdings;">l&nbsp;</span><span style="font-family: 宋体;">自定义</span>log4j<span style="font-family: 宋体;">和</span>logback<span style="font-family: 宋体;">的</span>appenders<span style="font-family: 宋体;">来产生数据和图表。</span></p>  <p style="margin-left: 21pt; text-indent: -21pt;"><span style="font-family: Wingdings;">l&nbsp;</span><span style="font-family: 宋体;">通过</span>jmx<span style="font-family: 宋体;">查看性能指标，并根据阈值发送消息。</span></p>  <p style="margin-left: 21pt; text-indent: -21pt;"><span style="font-family: Wingdings;">l&nbsp;</span>Web<span style="font-family: 宋体;">工程可以通过</span>servlet<span style="font-family: 宋体;">来输出性能指标。</span></p>  <p style="margin-left: 21pt; text-indent: -21pt;"><span style="font-family: Wingdings;">l&nbsp;</span>Perf4j<span style="font-family: 宋体;">可以和</span>aop<span style="font-family: 宋体;">等切面框架整合起来输出性能指标。</span></p>  <p style="margin-left: 21pt; text-indent: -21pt;"><span style="font-family: Wingdings;">l&nbsp;</span>Perf4j<span style="font-family: 宋体;">是一个可扩展的架构。</span></p>  </div><img src ="http://www.blogjava.net/yangpingyu/aggbug/374215.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yangpingyu/" target="_blank">yangpingyu</a> 2012-04-15 10:15 <a href="http://www.blogjava.net/yangpingyu/archive/2012/04/15/374215.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Maven与findbugs</title><link>http://www.blogjava.net/yangpingyu/archive/2012/04/14/374180.html</link><dc:creator>yangpingyu</dc:creator><author>yangpingyu</author><pubDate>Sat, 14 Apr 2012 10:55:00 GMT</pubDate><guid>http://www.blogjava.net/yangpingyu/archive/2012/04/14/374180.html</guid><wfw:comment>http://www.blogjava.net/yangpingyu/comments/374180.html</wfw:comment><comments>http://www.blogjava.net/yangpingyu/archive/2012/04/14/374180.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yangpingyu/comments/commentRss/374180.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yangpingyu/services/trackbacks/374180.html</trackback:ping><description><![CDATA[<div>      <p><span style="font-family: 宋体;">公司最近严抓软件质量问题，我抽空了解了下提高代码质量的一些开源工具。其中一个就是</span>findbugs<span style="font-family: 宋体;">。使用</span>findbugs<span style="font-family: 宋体;">有很多方式，比如：安装</span>eclipse findbugs<span style="font-family: 宋体;">插件，通过</span>maven<span style="font-family: 宋体;">调用生成报告。今天主要演示下</span>maven<span style="font-family: 宋体;">与</span>findbugs<span style="font-family: 宋体;">集成。</span></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体;">第一步：下载</span>maven<span style="font-family: 宋体;">，我使用的是</span>maven3<span style="font-family: 宋体;">。把</span>maven<span style="font-family: 宋体;">的命令加入</span>PATH<span style="font-family: 宋体;">环境变量。</span></p>  <p><span style="font-family: 宋体;">第二步：创建一个普通的</span>maven java<span style="font-family: 宋体;">工程。命令如下：</span>mvn archetype:maven-archetyp-quickstart &#8211;DgroupId=com.tianya &#8211;DartifactId=baowu<span style="font-family: 宋体;">。如果正常执行的话会生成如下结构的一个工程。</span></p>  <img src="http://www.blogjava.net/images/blogjava_net/yangpingyu/mavenfindbugs.jpg" alt="" width="246" border="0" height="217" />  <p><span style="font-family: 宋体;">第三步：我们看下</span>pom<span style="font-family: 宋体;">文件</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">project</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> <span style="color: #7f007f;">xmlns</span><span style="color: black;">=</span><em><span style="color: #2a00ff;">"http://maven.apache.org/POM/4.0.0"</span></em> <span style="color: #7f007f;">xmlns:xsi</span><span style="color: black;">=</span><em><span style="color: #2a00ff;">"http://www.w3.org/2001/XMLSchema-instance"</span></em></span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: #7f007f;">xsi:schemaLocation</span><span style="color: black;">=</span><em><span style="color: #2a00ff;">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span></em><span style="color: teal;">&gt;</span></span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">modelVersion</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">4.0.0</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">modelVersion</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">groupId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">com.tianya</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">groupId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">artifactId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">baowu</span></u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">artifactId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">version</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">0.0.1-SNAPSHOT</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">version</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">packaging</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">war</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">packaging</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left">&nbsp;</p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&lt;!--</span><span style="font-size: 10pt; font-family: 宋体; color: #3f5fbf;">配置插件来源</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;"> --&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">pluginRepositories</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">pluginRepository</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">id</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">Codehaus</span></u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> repository</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">id</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">url</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">http://repository.codehaus.org/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">url</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">pluginRepository</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">pluginRepositories</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">build</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">plugins</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">plugin</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">groupId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">org.codehaus.mojo</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">groupId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">artifactId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">findbugs</span></u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">-<u>maven</u>-<u>plugin</u></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">artifactId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">version</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">2.3.2</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">version</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">configuration</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&lt;!-- &lt;configLocation&gt;${<u>basedir</u>}/<u>springside</u>-findbugs.xml&lt;/configLocation&gt; --&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">threshold</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">High</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">threshold</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">effort</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">Default</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">effort</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">findbugsXmlOutput</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">true</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">findbugsXmlOutput</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&lt;!-- <u>findbugs</u>&nbsp;<u>xml</u></span><span style="font-size: 10pt; font-family: 宋体; color: #3f5fbf;">输出路径</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">--&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">findbugsXmlOutputDirectory</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">target/site</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">findbugsXmlOutputDirectory</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">configuration</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">plugin</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">plugins</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">build</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">project</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体;">我来解释下</span>xml<span style="font-family: 宋体;">配置：</span></p>  <p style="margin-left: 21pt; text-align: left; text-indent: -21pt;" align="left"><span style="font-family: Wingdings;">l&nbsp;</span><span style="font-family: 宋体;">配置插件下载地址</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&lt;!--</span><span style="font-size: 10pt; font-family: 宋体; color: #3f5fbf;">配置插件来源</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;"> --&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">pluginRepositories</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">pluginRepository</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">id</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">Codehaus</span></u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> repository</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">id</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">url</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">http://repository.codehaus.org/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">url</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">pluginRepository</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">pluginRepositories</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p>&nbsp;</p>  <p style="margin-left: 21pt; text-indent: -21pt;"><span style="font-family: Wingdings;">l&nbsp;</span><span style="font-family: 宋体;">由于</span>maven<span style="font-family: 宋体;">核心做的事情都是抽象的构建过程，很多实际的工作都是具体的插件来实现。所以很显然，</span>maven<span style="font-family: 宋体;">以插件的方式集成</span>findbugs<span style="font-family: 宋体;">。</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">plugin</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">groupId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">org.codehaus.mojo</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">groupId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">artifactId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">findbugs</span></u><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">-<u>maven</u>-<u>plugin</u></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">artifactId</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">version</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">2.3.2</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">version</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">configuration</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&lt;!-- &lt;configLocation&gt;${<u>basedir</u>}/<u>springside</u>-findbugs.xml&lt;/configLocation&gt; --&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&lt;!-- <u>findbugs</u>&nbsp;<u>xml</u></span><span style="font-size: 10pt; font-family: 宋体; color: #3f5fbf;">输出</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">--&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">findbugsXmlOutput</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">true</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">findbugsXmlOutput</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">&lt;!-- <u>findbugs</u>&nbsp;<u>xml</u></span><span style="font-size: 10pt; font-family: 宋体; color: #3f5fbf;">输出路径</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f5fbf;">--&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">findbugsXmlOutputDirectory</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">target/site</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">findbugsXmlOutputDirectory</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">configuration</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">plugin</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>  <p>&nbsp;</p>  <p style="margin-left: 21pt; text-indent: -21pt;"><span style="font-family: Wingdings;">l&nbsp;</span><span style="font-family: 宋体;">大家注意到了</span>findbugs<span style="font-family: 宋体;">插件里，我注释掉了一句话，其实这句话就是可以使用自己的</span>fingbugs<span style="font-family: 宋体;">配置来做检查。我用的是</span>springside<span style="font-family: 宋体;">的一个</span>xml<span style="font-family: 宋体;">文件。</span></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体;">第四步：配置好相关文件之后，接下来就是执行相关命令了。</span></p>  <p>mvn compile findbugs:findbugs<span style="font-family: 宋体;">生成报告。报告生成的地址就是</span>${<span style="font-family: 宋体;">项目根目录</span>}/<span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">target/site</span><span style="font-size: 10pt; font-family: 宋体; color: black;">。也可以通过</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">mvn findbugs:gui gui</span><span style="font-family: 宋体;">界面查看</span><span>findbugs</span><span style="font-family: 宋体;">的</span><span>report</span><span style="font-family: 宋体;">。</span></p>  </div><img src ="http://www.blogjava.net/yangpingyu/aggbug/374180.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yangpingyu/" target="_blank">yangpingyu</a> 2012-04-14 18:55 <a href="http://www.blogjava.net/yangpingyu/archive/2012/04/14/374180.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习书单和资料</title><link>http://www.blogjava.net/yangpingyu/archive/2012/02/07/369530.html</link><dc:creator>yangpingyu</dc:creator><author>yangpingyu</author><pubDate>Tue, 07 Feb 2012 05:45:00 GMT</pubDate><guid>http://www.blogjava.net/yangpingyu/archive/2012/02/07/369530.html</guid><wfw:comment>http://www.blogjava.net/yangpingyu/comments/369530.html</wfw:comment><comments>http://www.blogjava.net/yangpingyu/archive/2012/02/07/369530.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yangpingyu/comments/commentRss/369530.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yangpingyu/services/trackbacks/369530.html</trackback:ping><description><![CDATA[<div>  <p style="text-indent:21.0pt"><span style="font-family:宋体;">从学校毕业到工作已经</span>2<span style="font-family:宋体;">年半时间了，在豆瓣、当当、京东和亚玛逊上关注了很多书籍，也比较喜欢逛书店。当然买了很多和看了部分，自己家里很多书还没看（人类的惰性，借口）。在这两年半时间内，走了一些弯路，所以想总结下自己的学习生涯。</span></p>  <p style="text-indent:21.0pt">&nbsp;</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;">毕业的时候去了一家创业型的互联网公司，在这家公司没有任何培训机制，任何东西都需要靠自己来捉摸。根据工作需要看了</span>struts2<span style="font-family:宋体;">，</span>spring<span style="font-family:宋体;">，</span>hibernate<span style="font-family:宋体;">，</span>jstl<span style="font-family:宋体;">，</span>jsp<span style="font-family:宋体;">，</span>servlet<span style="font-family:宋体;">等一些</span>J2EE<span style="font-family:宋体;">相关组件的书和资料。仅靠这些技术也能搭建出一个符合产品的网站。接触到</span>infoq<span style="font-family:宋体;">网站之后，了解了一些大型网站的架构变迁等技术，在一年的时间内不断追寻这些不符合自己目前需要的技术，充其量就是开阔了自己技术的眼界。由于互联网公司的一些劣势，导致我有了跳槽的想法，但是出去面试之后，才知道自己是井底之蛙。自己也算热爱技术，也算努力学习和研究的，自己反思和总结了一下：<strong><span style="color:red">不注重基础。</span></strong></span></p>  <p style="text-indent:21.0pt">&nbsp;</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;">那么学习什么才算基础呢？我主要列举下我的学习书单：</span></p>  <p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p style="margin-left:42.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">&#252;&nbsp;</span><span style="font-family:宋体;">计算机基础：任何软件运行的基础。</span></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1230413/"><span style="font-family:宋体;"><span>深入理解计算机系统（修订版）</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/6014550/"><span style="font-family:宋体;"><span>计算机组成原<span>理</span></span></span></a></p>  <p>&nbsp;</p>  <p style="margin-left:42.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">&#252;&nbsp;</span><span style="font-family:宋体;">操作系统：硬件管理的软件，我们的应用软件主要依赖于操作系统。</span></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/4889838/"><span style="font-family:宋体;"><span>鸟哥的</span>Linux<span style="font-family:宋体;">私房菜</span> <span style="font-family:宋体;">基础学习篇</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1689876/"><span style="font-family:宋体;"><span>操作系统原理</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1503819/">Linux<span style="font-family:宋体;"><span>内核设计与实现</span></span></a></p>  <p>&nbsp;</p>  <p style="margin-left:42.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">&#252;&nbsp;</span><span style="font-family:宋体;">数据结构：软件</span>=<span style="font-family:宋体;">数据结构</span>+<span style="font-family:宋体;">算法。其实操作系统软件和应用软件都在大量应用数据结构。</span></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/6424904/"><span style="font-family:宋体;"><span>大话数据结构</span></span></a></p>  <p style="margin-left:21.0pt">&nbsp;</p>  <p style="margin-left:42.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">&#252;&nbsp;</span><span style="font-family:宋体;">网络：系统一定需要与外部交互，那就需要网络。</span></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1179807/"><span style="font-family:宋体;"><span>计算机网络</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1088054/">TCP/IP<span style="font-family:宋体;"><span>详解</span> <span style="font-family:宋体;">卷</span>1</span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1087767/">TCP/IP<span style="font-family:宋体;"><span>详解</span> <span style="font-family:宋体;">卷</span>2</span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1058634/">TCP/IP<span style="font-family:宋体;"><span>详解</span> <span style="font-family:宋体;">卷</span>3</span></a></p>    <p style="margin-left:42.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">&#252;&nbsp;</span><span style="font-family:宋体;">数据库：存储数据。</span></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1945005/"><span style="font-family:宋体;"><span>数据库系统概论</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1909003/">MySQL 5 <span style="font-family:宋体;"><span>权威指南</span>-(<span style="font-family:宋体;">第</span>3<span style="font-family:宋体;">版</span>)</span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/3729677/">MySQL<span style="font-family:宋体;"><span>性能调优与架构设计</span></span></a></p>  <p style="margin-left:21.0pt">&nbsp;</p>  <p style="margin-left:42.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">&#252;&nbsp;</span><span style="font-family:宋体;">软件工程：开发软件是一个大工程，需要有一套理论来管理软件开发。</span></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/5957488/"><span style="font-family:宋体;"><span>软件工程</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1140457/"><span style="font-family:宋体;"><span>敏捷软件开发</span></span></a></p>  <p>&nbsp;</p>  <p style="margin-left:42.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">&#252;&nbsp;</span><span style="font-family:宋体;">算法：尚未接触。</span></p>  <p style="margin-left:21.0pt">&nbsp;</p>  <p style="margin-left:42.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">&#252;&nbsp;</span>Java<span style="font-family:宋体;">基础：具体的高级语言，最好的学习地方就是</span>java<span style="font-family:宋体;">的官方网站和开源代码。</span> </p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/2057790/">Java JDK6<span style="font-family:宋体;"><span>学习笔记</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/3360807/">Effective Java<span style="font-family:宋体;"><span>中文版</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/2130190/">Java<span style="font-family:宋体;"><span>编程思想</span> <span style="font-family:宋体;">（第</span>4<span style="font-family:宋体;">版）</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1438754/">Java<span style="font-family:宋体;"><span>网络编程</span>(<span style="font-family:宋体;">中文版</span> <span style="font-family: 宋体;">第三版</span>)</span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/2148132/">JAVA<span style="font-family:宋体;"><span>并发编程实践</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/6522893/"><span style="font-family:宋体;"><span>深入理解</span>Java<span style="font-family:宋体;">虚拟机</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1754542/">Spring in Action<span style="font-family:宋体;"><span>中文版</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1315047/"><span style="font-family:宋体;"><span>深入浅出</span>Hibernate</span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/2254524/">Struts2<span style="font-family:宋体;"><span>权威指南</span></span></a></p>  <p>&nbsp;</p>  <p style="margin-left:42.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">&#252;&nbsp;</span>Java<span style="font-family:宋体;">进阶：面向对象思想、设计模式和</span>J2EE<span style="font-family:宋体;">深入。</span> </p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1214074/">Java<span style="font-family:宋体;"><span>与模式</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/4826290/"><span style="font-family:宋体;"><span>企业应用架构模式</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/2112652/">POJOs IN ACTION<span style="font-family:宋体;"><span>中文版</span></span></a></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><a href="http://book.douban.com/subject/1119852/">J2EE<span style="font-family:宋体;"><span>设计开发编程指南</span></span></a><span style="font-family:宋体;">（</span><span>Expert One-on-One J2EE Design and Development</span><span style="font-family:宋体;">）</span></p>  <p style="margin-left:63.0pt;text-indent:-21.0pt;"><span style="font-family:Wingdings;">n&nbsp;</span><span><a href="http://book.douban.com/subject/1426848/">Expert One-on-One J2EE Development without EJB</a></span></p>  <p style="margin-left:42.0pt;text-indent:0cm;">&nbsp;</p>  <p style="margin-left:21.0pt"><span style="font-family:宋体;">学习了这些基础之后，我们在来说分布式，</span>nosql<span style="font-family:宋体;">，云计算，企业集成等等。只有掌握了基础我们才能更好的创新。</span></p>  </div><img src ="http://www.blogjava.net/yangpingyu/aggbug/369530.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yangpingyu/" target="_blank">yangpingyu</a> 2012-02-07 13:45 <a href="http://www.blogjava.net/yangpingyu/archive/2012/02/07/369530.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>jvm运行时数据区域</title><link>http://www.blogjava.net/yangpingyu/archive/2012/02/07/369508.html</link><dc:creator>yangpingyu</dc:creator><author>yangpingyu</author><pubDate>Tue, 07 Feb 2012 02:27:00 GMT</pubDate><guid>http://www.blogjava.net/yangpingyu/archive/2012/02/07/369508.html</guid><wfw:comment>http://www.blogjava.net/yangpingyu/comments/369508.html</wfw:comment><comments>http://www.blogjava.net/yangpingyu/archive/2012/02/07/369508.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yangpingyu/comments/commentRss/369508.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yangpingyu/services/trackbacks/369508.html</trackback:ping><description><![CDATA[<div>  <p><span style="font-size:12.0pt">Java</span><span style="font-size:12.0pt;font-family:宋体;">语言与</span><span style="font-size:12.0pt">c</span><span style="font-size:12.0pt; font-family:宋体;">语言有一个非常重要的区别就是：内存管理方式的不同，</span><span style="font-size:12.0pt">java</span><span style="font-size:12.0pt; font-family:宋体;">语言内存管理不需要程序开发人员关注，而</span><span style="font-size:12.0pt">c</span><span style="font-size:12.0pt; font-family:宋体;">语言的内存的请求和释放都是开发人员来处理。辩证的思维来看，不同内存管理实现方式有优点和缺点，所以语言应用的场景，效率会有很大不同。</span></p>  <p>&nbsp;</p>  <p><span style="font-size:12.0pt">Jvm</span><span style="font-size:12.0pt;font-family:宋体;">运行时的数据区域主要有：程序计数器、虚拟机栈、本地方法栈、方法区和堆。其中程序计数器、虚拟机栈和本地方法栈是线程独享，而方法区和堆是所有线程共享。</span></p>  <p style="margin-left:21.0pt;text-indent:-21.0pt;"><span style="font-size:12.0pt;font-family:Wingdings;">&#252;&nbsp;</span><span style="font-size:12.0pt;font-family:宋体;">程序计数器：</span><span style="font-size:12.0pt">jvm</span><span style="font-size:12.0pt; font-family:宋体;">每个线程都有一个程序计数器。在任一时刻都有一个线程的方法在运行，如果这个方法不是本地方法，那么程序计数器存放的就是正在执行的指令地址；如果是本地方法，那么程序计数器中存放的指定地址为</span><span style="font-size:12.0pt">undefined</span><span style="font-size: 12.0pt;font-family:宋体;">。</span></p>  <p style="margin-left:21.0pt;text-indent:-21.0pt;"><span style="font-size:12.0pt;font-family:Wingdings;">&#252;&nbsp;</span><span style="font-size:12.0pt;font-family:宋体;">虚拟机栈：当</span><span style="font-size:12.0pt">jvm</span><span style="font-size:12.0pt; font-family:宋体;">创建一个线程的时候就会为线程分配一个虚拟机栈。主要用于存放方法的一些本地变量和部分结果，一般这里的大小都是固定，但不是绝对。一个方法的执行到完成就是栈的入栈和出栈。假设在某方法中定义了一个对象</span><span style="font-size:12.0pt">Object obj=new Object();</span><span style="font-size:12.0pt;font-family:宋体;">其中</span><span style="font-size:12.0pt">obj</span><span style="font-size:12.0pt; font-family:宋体;">是存放在栈上，而</span><span style="font-size:12.0pt">new Object()</span><span style="font-size:12.0pt; font-family:宋体;">是在堆上分配。</span><span style="font-size:12.0pt">-Xss</span><span style="font-size:12.0pt;font-family: 宋体;">可以控制</span><span style="font-size: 12.0pt">jvm</span><span style="font-size:12.0pt;font-family:宋体;">虚拟机栈的大小。</span></p>  <p style="margin-left:21.0pt;text-indent:-21.0pt;"><span style="font-size:12.0pt;font-family:Wingdings;">&#252;&nbsp;</span><span style="font-size:12.0pt;font-family:宋体;">本地方法栈：大体跟虚拟机栈类似，不过是给本地方法使用的。虚拟机栈和本地方法栈在</span><span style="font-size:12.0pt">hotspot</span><span style="font-size:12.0pt; font-family:宋体;">是没有分开实现的，而是统称为栈。</span></p>  <p style="margin-left:21.0pt;text-indent:-21.0pt;"><span style="font-size:12.0pt;font-family:Wingdings;">&#252;&nbsp;</span><span style="font-size:12.0pt;font-family:宋体;">方法区：主要存放静态变量，常量，类加载器加载的类等一些信息。</span></p>  <p style="margin-left:21.0pt;text-indent:-21.0pt;"><span style="font-size:12.0pt;font-family:Wingdings;">&#252;&nbsp;</span><span style="font-size:12.0pt;font-family:宋体;">堆：</span><span style="font-size:12.0pt">jvm</span><span style="font-size:12.0pt; font-family:宋体;">绝大部分的对象分配都在堆上分配。</span><span style="font-size:12.0pt">-Xmn &#8211;Xmx</span><span style="font-size: 12.0pt;font-family:宋体;">是控制堆最小值和最大值，一般堆的大小在使用了超过</span><span style="font-size:12.0pt">mx</span><span style="font-size:12.0pt; font-family:宋体;">设定的</span><span style="font-size:12.0pt">70%</span><span style="font-size:12.0pt;font-family: 宋体;">的时候，就会自动扩大到最大值，所以防止这种扩大和缩小我们设置成一样的值。</span></p>  </div><img src ="http://www.blogjava.net/yangpingyu/aggbug/369508.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yangpingyu/" target="_blank">yangpingyu</a> 2012-02-07 10:27 <a href="http://www.blogjava.net/yangpingyu/archive/2012/02/07/369508.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ClassCastException</title><link>http://www.blogjava.net/yangpingyu/archive/2012/01/10/368240.html</link><dc:creator>yangpingyu</dc:creator><author>yangpingyu</author><pubDate>Tue, 10 Jan 2012 08:07:00 GMT</pubDate><guid>http://www.blogjava.net/yangpingyu/archive/2012/01/10/368240.html</guid><wfw:comment>http://www.blogjava.net/yangpingyu/comments/368240.html</wfw:comment><comments>http://www.blogjava.net/yangpingyu/archive/2012/01/10/368240.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yangpingyu/comments/commentRss/368240.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yangpingyu/services/trackbacks/368240.html</trackback:ping><description><![CDATA[<div>  <p>ClassCastException<span style="font-family:宋体;">类型转换异常，是一个运行时异常。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">非常常见就是不同类型之间的强制类型转换就会抛出</span>ClassCastException<span style="font-family:宋体;">异常。还有一种就是不同</span>ClassLoader<span style="font-family:宋体;">加载的相同的类型转换也会抛出</span>ClassCastException<span style="font-family:宋体;">。接下来我用代码来详细解释下。</span></p>  <p>&nbsp;</p>  <p style="margin-left:18.0pt;text-indent:-18.0pt;"><span>1、&nbsp;</span><span style="font-family:宋体;">强制类型转换</span></p>  <p style="text-align:left;text-autospace:none" align="left"><strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">public</span></strong> <strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">class</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;"> ClassCastExceptionTest {</span></p>  <p style="text-align:left;text-autospace:none" align="left">&nbsp;</p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;; color:#3F5FBF;">/**</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:#3F5FBF;">&nbsp;&nbsp;&nbsp; &nbsp;* </span><strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#7F9FBF;">@param</span></strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#3F5FBF;"> args</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:#3F5FBF;">&nbsp;&nbsp;&nbsp; &nbsp;*/</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:#7F0055;">public</span></strong> <strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">static</span></strong> <strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">void</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;"> main(String[] args) {</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Animal a1 = </span><strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">new</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;"> Dog();&nbsp;</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#3F7F5F;">//1</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Animal a2 = </span><strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">new</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;"> Cat();&nbsp;</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#3F7F5F;">//2</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dog <u>d1</u> = (Dog)a1;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;; color:#3F7F5F;">//3</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dog <u>d2</u> = (Dog)a2;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;; color:#3F7F5F;">//4</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp; }</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">}</span></p>  <p><span style="font-family:宋体;">把猫转换成狗，是不对的。后面注释为</span>4<span style="font-family:宋体;">的代码是无法正常赋值的。</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:red;">Exception in thread "main" </span><u><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:navy;">java.lang.ClassCastException</span></u><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:red;">: Cat cannot be cast to Dog</span></p>  <p><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;; color:red;">&nbsp;&nbsp;&nbsp; at ClassCastExceptionTest.main(</span><u><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:navy;">ClassCastExceptionTest.java:13</span></u><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:red;">)</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p style="margin-left:18.0pt;text-indent:-18.0pt;"><span>2、&nbsp;</span><span style="font-family:宋体;">不同</span>classloader<span style="font-family:宋体;">加载相同类型类之间的转换</span></p>  <p style="text-align:left;text-autospace:none" align="left"><strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">import</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;"> java.io.File;</span></p>  <p style="text-align:left;text-autospace:none" align="left"><strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">import</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;"> java.net.URL;</span></p>  <p style="text-align:left;text-autospace:none" align="left"><strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">import</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;"> java.net.URLClassLoader;</span></p>  <p style="text-align:left;text-autospace:none" align="left">&nbsp;</p>  <p style="text-align:left;text-autospace:none" align="left">&nbsp;</p>  <p style="text-align:left;text-autospace:none" align="left"><strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">public</span></strong> <strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">class</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;"> ClassCastExceptionTest {</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp; </span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;; color:#3F5FBF;">/**</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:#3F5FBF;">&nbsp;&nbsp;&nbsp; &nbsp;* </span><strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#7F9FBF;">@param</span></strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#3F5FBF;"> args</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:#3F5FBF;">&nbsp;&nbsp;&nbsp; &nbsp;*/</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:#7F0055;">public</span></strong> <strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">static</span></strong> <strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">void</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;"> main(String[] args) </span><strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#7F0055;">throws</span></strong><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;"> Exception {</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File file = </span><strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:#7F0055;">new</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;"> File(Thread.<em>currentThread</em>().getContextClassLoader().getResource(</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF;">""</span><span style="font-size: 10.0pt;font-family:&quot;Courier New&quot;;color:black;">).getPath());</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; URL[] urls = {file.<s><u>toURL</u></s><u>()</u>};</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; URLClassLoader classloader1 = </span><strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#7F0055;">new</span></strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;; color:black;"> URLClassLoader(urls, ClassLoader.<em>getSystemClassLoader</em>().getParent());</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>Class</u> classloader1Animal1 = classloader1.loadClass(</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF;">"Dog"</span><span style="font-size: 10.0pt;font-family:&quot;Courier New&quot;;color:black;">);</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dog <u>dog1</u> = (Dog)classloader1Animal1.newInstance();</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; URLClassLoader <u>classloader2</u> = </span><strong><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#7F0055;">new</span></strong><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:black;"> URLClassLoader(urls, ClassLoader.<em>getSystemClassLoader</em>().getParent());</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>Class</u> <u>classloader1Animal2</u> = classloader1.loadClass(</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#2A00FF;">"Dog"</span><span style="font-size: 10.0pt;font-family:&quot;Courier New&quot;;color:black;">);</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dog dog2 = (Dog)classloader1Animal1.newInstance();</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dog1 = dog2;</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">&nbsp;&nbsp;&nbsp; }</span></p>  <p style="text-align:left;text-autospace:none" align="left">&nbsp;</p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:black;">}</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">代码中我们看到</span>dog1=dog2<span style="font-family:宋体;">，这样赋值是会抛异常的。</span></p>  <p style="text-align:left;text-autospace:none" align="left"><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:red;">Exception in thread "main" </span><u><span style="font-size:10.0pt;font-family: &quot;Courier New&quot;;color:navy;">java.lang.ClassCastException</span></u><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:red;">: Dog cannot be cast to Dog</span></p>  <p><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;; color:red;">&nbsp;&nbsp;&nbsp; at ClassCastExceptionTest.main(</span><u><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;;color:navy;">ClassCastExceptionTest.java:17</span></u><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:red;">)</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体; background:yellow;">以后大家遇到</span><span style="background:yellow;">classCastException</span><span style="font-family:宋体;background:yellow;">的时候要注意了，不一定是强制类型转换导致的，也有可能不同的</span><span style="background:yellow;">classloader</span><span style="font-family:宋体;background:yellow;">加载了相同的类，然后这个类不同的实例进行赋值。</span></p>  </div><img src ="http://www.blogjava.net/yangpingyu/aggbug/368240.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yangpingyu/" target="_blank">yangpingyu</a> 2012-01-10 16:07 <a href="http://www.blogjava.net/yangpingyu/archive/2012/01/10/368240.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>