﻿<?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-向左走向右走-随笔分类-java</title><link>http://www.blogjava.net/midstr/category/24101.html</link><description>人生總有許多的意外, 
握在手裡的風箏也會... 
突然斷了線——人生總有許多的巧合，
兩條平行綫也可能會...
有交滙的一天</description><language>zh-cn</language><lastBuildDate>Fri, 23 May 2008 05:51:01 GMT</lastBuildDate><pubDate>Fri, 23 May 2008 05:51:01 GMT</pubDate><ttl>60</ttl><item><title>java性能测试工具</title><link>http://www.blogjava.net/midstr/archive/2008/05/22/202202.html</link><dc:creator>向左走向右走</dc:creator><author>向左走向右走</author><pubDate>Thu, 22 May 2008 08:36:00 GMT</pubDate><guid>http://www.blogjava.net/midstr/archive/2008/05/22/202202.html</guid><wfw:comment>http://www.blogjava.net/midstr/comments/202202.html</wfw:comment><comments>http://www.blogjava.net/midstr/archive/2008/05/22/202202.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/midstr/comments/commentRss/202202.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/midstr/services/trackbacks/202202.html</trackback:ping><description><![CDATA[&nbsp; 商业工具&nbsp;&nbsp;<a title="三款java分析器点评" href="http://www.yesky.com/SoftChannel/72342371961929728/20031005/1733975.shtml">三款java分析器点评</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1、Jprofiler ej-techologies&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2、Borland Optimizeit Suite <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3、Quest Jprobe Quest Software&nbsp;<br />
<br />
&nbsp; 免费工具<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4、Eclipse&nbsp;Profiler&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font style="background-color: #cce8cf"><a href="http://sourceforge.net/projects/eclipsecolorer/">http://sourceforge.net/projects/eclipsecolorer/</a></font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5、netbeans Profile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<font style="background-color: #cce8cf"><a href="http://profiler.netbeans.org/index.html">http://profiler.netbeans.org/index.html</a></font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6、Eclipse TPTP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font style="background-color: #cce8cf"><a href="http://www.eclipse.org/tptp/">http://www.eclipse.org/tptp/</a></font><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a title="open source profiler for java" href="http://www.manageability.org/blog/stuff/open-source-profilers-for-java/view">open source profiler for java</a>&nbsp;&nbsp; zz
<blockquote>
<ul>
    <li><a href="http://profiler.cougaar.org/">Cougaar Memory Profiler<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - The Cougaar memory profiler is a tool for debugging memory usage and leaks in any Java application. It features a scalable 100% Java design that is lighter weight than existing JVMPI-based profilers. The profiler tracks memory usage within the application by using tables of WeakReferences.
    <li><a href="http://oss.metaparadigm.com/jmemprof/">JMemProf<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - JMemProf is a live Java memory profiler suitable for deployment in web containers such as JBoss, Tomcat and others. JMemProf allows you to retrieve memory profile information while your application is running. JMemProf aims to add dynamic visibility to memory usage in Java web applications; memory profile information can be viewed easily through a Servlet based web interface while the application is running. It is much more dynamic and easily understandable than that of the hprof heap profiler bundled with the J2SDK.
    <li><a href="http://www.khelekore.org/jmp/">JMP<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - JMP is a profiler for java that can be used to trace objects usage and method timings. JMP uses the JVMPI interface to gather statistics and interact with the JVM. JMP uses a GTK+ interface to show the status.
    <li><a href="http://ejp.sourceforge.net/">Extensible Java Profiler<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - Extensible Java Profiler (EJP) is a profiling tool for Java with a scalable and extensible architecture, allowing its usage for exotic programming languages that use a Java backend. EJP is based on the Java Virtual Machine Profiler Interface (JVMPI). It can be used to trace the execution of small parts of Java programs and display it in hierarchical trees with some elements hidden or highlighted.
    <li><a href="http://www.javaperformancetuning.com/tools/jamon/index.shtml">JAMon <img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a>- The Java Application Monitor (JAMon) is a free, simple, high performance, thread safe, Java API that allows developers to easily monitor production applications. JAMon can be used to determine application performance bottlenecks, user/application interactions, and application scalability. JAMon gathers summary statistics such as hits, execution times (total, average, minimum, maximum, standard deviation), and simultaneous application requests. JAMon statistics are displayed in the sortable JAMon report.
    <li><a href="http://jmechanic.sourceforge.net/">jMechanic<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - jMechanic is an Eclipse Java IDE plugin providing Java Profiling tools. Tools such as CPU Sampling and Heap Summary allow the Java developer to tune up the performance of their Java programs all within the comfort of the Eclipse IDE.
    <li><a href="http://jrat.sourceforge.net/">JRat<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - JRat is the Java Runtime Analysis Toolkit. Its purpose is to enable developers to better understand the runtime behavior of their Java programs. There are currently a number of ways JRat can monitor an application (i.e. Bytecode instrumentation, JBoss AOP, Dynamic Proxies, JDI).
    <li><a href="http://eclipsecolorer.sourceforge.net/index_profiler.html">Eclipse Profiler<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - This is a plugin for the Eclipse platform which allows java code profiling.
    <li><a href="http://xdprof.sourceforge.net/">xdProf<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - xdProf is a cross-platform tool that captures and analyzes stack traces sent at a fixed interval from Java Virtual Machines in a distributed system. The performance impact of the xdProf client sending data over a local area network is minimal: less than a 8% increase in total elapsed time for a set of standard benchmarks.
    <li><a href="http://www.eclipse.org/hyades/">Hyades<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - Hyades is an integrated test, trace and monitoring environment, based on Eclipse, that provides standards, tools and tool interoperability across the test process.
    <li><a href="http://www.experimentalstuff.com/Technologies/GCspy/">GCSpy <img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a>- The Garbage Collector Spy Tool, or GCspy for short, is a generic and highly-adaptable heap visualisation framework, designed to visualise a wide range of memory management systems, whether they depend on garbage collection or implement explicit de-allocation.
    <li><a href="http://www.virtualmachine.de/">heapprofile<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - A zero-overhead JVMPI plugin for finding first indications of memory leaks in production environments. Where commercial tools kill the performance of your application by collecting uninteresting performance data (such as 'who allocated this object'), this plugin stays inactive during runtime and simply dumps a very simple image of the Java heap on request.
    <li><a href="http://www.sable.mcgill.ca/~bdufou1/AdaptJ/main.html">AdaptJ<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - The AdaptJ Agent allows to collect event trace data from a Java program running in a Java Virtual Machine. The AdaptJ Analysis Tool allows to read and analyze the traces generated by the agent, using either the built-in analyses or custom ones.
    <li><a href="http://jcoverage.sourceforge.net/">JavaTreeProfiler<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - JVMPI based visualization using a TreeMap.
    <li><a href="http://besee.sourceforge.net/index.html">beeSee 2<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - beSee 2 provides a mechanism to plug a class preprocessor instrumentation layer in any classloader hierarchy, thus supporting java 1.3, 1.4, J2SE and J2EE environment. beSee 2 is the ground 0 lightweight layer of the next generation AOP architecture. It provides a bytecode kit independant solution and comes ready to use with two implementation: BCEL and Javassist.
    <li><a href="http://www.lambdacs.com/debugger/debugger.html">Omniscient Debugging<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - The debugger works by collecting "time stamps" which record everything that happens in a program. A GUI then allows you to navigate backwards in time to look at objects, variables, method calls, etc. Although focused on debugging, technique may be applicable for Profilers.
    <li><a href="http://developers.sun.com/dev/coolstuff/hotswap/">HotSwap Client Tool<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - This is a GUI client tool that provides access to the HotSwap functionality. Using this tool, you can dramatically improve the time of the usual "test - find a bug - stop the program - change - recompile - restart the program" development cycle by removing the "stop" and "restart" elements from it. Furthermore, you can use it to patch "on-the-fly" deployed applications that need to run uninterrupted.
    <li><a href="http://www.sable.mcgill.ca/step/">STEP<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - Extsnible Program Trace Encoding. STEP providins a standard method for encoding general program trace data in a flexible and compact format. The system consists of a trace data definition language along with a compiler for the language and an encoding architecture that implements a number of common trace reduction techniques. The system simplifies the development and interoperability of trace clients by encapsulating the encoding process and presenting the data as an abstract object stream.
    <li><a href="http://appstats.sourceforge.net/">AppStats <img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a>- AppStats is a lightweight, open source framework developed and used by Grand Central Communications, Inc. to capture, analyze, and publicize health, performance, and monitoring statistics for Java applications.
    <li><a href="http://www.p6spy.com/index.html">P6Spy<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - P6Spy is an open source framework for applications that intercept and optionally modify database statements. P6Log intercepts and logs the database statements of any application that uses JDBC. P6Outage detects long-running statements that may be indicative of a database outage proble and will log any statement that surpasses the configurable time boundary during its execution. P6Outage was designed to minimize any logging performance penalty by logging only long running statements.
    <li><a href="http://profiler.netbeans.org/index.html">NetBeans Profiler<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - NetBeans Profiler is a project to integrate the JFluid profiling technoglogy, which is being developed by Sun, into the NetBeans IDE. The JFluid technology addresses this issue by providing a mechanism in the JVM(tm), which allows the user to turn profiling on and off at any time, and, equally important, to profile just a small subset of the code, that they are currently interested in. The profiled subset of the code and the type of profiling (CPU, memory, etc.) can be changed at any moment at run time. This is achieved mainly through dynamic bytecode instrumentation. Features include low overhead profiling, attaching to running applications, CPU Performance profiling, memory profiling, memory leak debugging and task-based profiling.
    <li><a href="http://fprofiler.sourceforge.net/">FProfiler<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - FProfiler is a Java Profiler using BCEL and log4j. Its very fast because it inserts the needed instructions into the Bytecode of the classes. It can be used to find Hotspots in Java programs, libs and servlet environments simply every Java class.
    <li><span class="link-https"><a href="https://hat.dev.java.net/">Heap Analysis Tool(HAT)</a></span> - The Heap Analysis Tool (HAT) helps to debug unnecessary object retention (sometimes called "memory leaks") by providing a convenient means to browse the object topology in a heap snapshot, which is generated by the Java VM. HAT reads a hprof file, then sets itself up as a web server--therefore allowing you to run queries against a heap dump contained within the hprof file.
    <li><a href="http://infrared.sourceforge.net/">InfraRED<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - InfraRED is a tool for monitoring performance of a J2EE application and diagnosing performance problems. It collects metrics about various aspects of an application&#8217;s performance and makes it available for quantitative analysis of the application. InfraRED uses AOP to weave the performance monitoring code into the application.
    <li><span class="link-https"><a href="https://glassbox-inspector.dev.java.net/">Glassbox Inspector</a></span> - The Glassbox Inspector project combines AspectJ and JMX for a flexible, modular approach to monitoring performance for enterprise systems. It provides correlated information to allow you to identify specific problems, but with low enough overhead to be used in production environments. It lets you capture statistics such as total counts, total time, and worst-case performance for requests, and will also let let you drill down into that information for database calls within a request.
    <li><a href="http://jiprof.sourceforge.net/">JIP<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - JIP is a code profiling tool much like the hprof tool that ships with the JDK. JIP allows you to turn the profiler on and off while the JVM is running. JIP is pure Java. It takes advantage of the Java5&#8482; feature which allows you to hook the classloader. When the profiler is turned off, there is almost no overhead associated with using JIP. JIP allows real world timings for every class in your code.
    <li><a href="http://www.mcs.vuw.ac.nz/~djp/djprof/">DJProf<img class="snap_preview_icon" id="snap_com_shot_link_icon" style="border-top-width: 0px; padding-right: 0px; background-position: -1058px 0px; display: inline; padding-left: 0px; font-weight: normal; border-left-width: 0px; min-height: 0px; left: auto; float: none; background-image: url(http://i.ixnp.com/images/v3.30/theme/silver/palette.gif); visibility: visible; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; width: 14px; line-height: normal; padding-top: 1px; background-repeat: no-repeat; font-style: normal; font-family: 'trebuchet ms', arial, helvetica, sans-serif; position: static; top: auto; height: 12px; background-color: transparent; border-right-width: 0px; text-decoration: none; maxheight: 2000px; maxwidth: 2000px; minwidth: 0px; cssfloat: none" alt="" src="http://i.ixnp.com/images/v3.30/t.gif" /></a> - DJProf is an experimental Java profiling tool which employs AspectJ to insert the necessary instrumentation for profiling rather than, for example, the Java Machine Profiler Interface (JVMPI). DJProf can be used to profile Java programs without modification (i.e. there is no need to recompile them for profiling) and does not require the user to have any knowledge of AspectJ. The Load-Time Weaving capability of AspectJ is utilised to make this possible. It supports several different modes of profiling such as heap usage, object lifetime, wasted time and time spent. </li>
</ul>
</blockquote>
<img src ="http://www.blogjava.net/midstr/aggbug/202202.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/midstr/" target="_blank">向左走向右走</a> 2008-05-22 16:36 <a href="http://www.blogjava.net/midstr/archive/2008/05/22/202202.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>增加静态方法要重启tomcat？</title><link>http://www.blogjava.net/midstr/archive/2008/04/21/194488.html</link><dc:creator>向左走向右走</dc:creator><author>向左走向右走</author><pubDate>Mon, 21 Apr 2008 04:54:00 GMT</pubDate><guid>http://www.blogjava.net/midstr/archive/2008/04/21/194488.html</guid><wfw:comment>http://www.blogjava.net/midstr/comments/194488.html</wfw:comment><comments>http://www.blogjava.net/midstr/archive/2008/04/21/194488.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/midstr/comments/commentRss/194488.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/midstr/services/trackbacks/194488.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在开发过程中，给 <font style="background-color: #cce8cf">com.thunisoft.fy.business.sp.SelectListUtils 新增加了一个public static方法 <font style="background-color: #cce8cf">getTestSelectList()。在页面的处理的logic类里面使用的时候代码提示都可以提示出来，调用方法也没有报编译期错误。刷新界面后，后台运行到刚才调用的地方就报如下错误：</font></font><br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">2008</span><span style="color: #000000">-</span><span style="color: #000000">04</span><span style="color: #000000">-</span><span style="color: #000000">21</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">12</span><span style="color: #000000">:</span><span style="color: #000000">30</span><span style="color: #000000">:</span><span style="color: #000000">27</span><span style="color: #000000">,</span><span style="color: #000000">032</span><span style="color: #000000">&nbsp;[com.thunisoft.summer.web.action.BaseAction]</span><span style="color: #000000">-</span><span style="color: #000000">[ERROR]&nbsp;runtime&nbsp;exception<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />java.lang.NoSuchMethodError:&nbsp;com.thunisoft.fy.business.sp.SelectListUtils.getTestSelectList()Lcom</span><span style="color: #000000">/</span><span style="color: #000000">thunisoft</span><span style="color: #000000">/</span><span style="color: #000000">fy</span><span style="color: #000000">/</span><span style="color: #000000">support</span><span style="color: #000000">/</span><span style="color: #000000">selectObj</span><span style="color: #000000">/</span><span style="color: #000000">SelectList;<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.thunisoft.fy.spxt.pub.ajxq.AjxqLogic.displayZxAjxq_right(AjxqLogic.java:</span><span style="color: #000000">736</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.thunisoft.fy.spxt.pub.ajxq.AjxqLogic.displayAjxq_right(AjxqLogic.java:</span><span style="color: #000000">116</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;sun.reflect.NativeMethodAccessorImpl.invoke0(Native&nbsp;Method)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:</span><span style="color: #000000">39</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:</span><span style="color: #000000">25</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;java.lang.reflect.Method.invoke(Method.java:</span><span style="color: #000000">324</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.thunisoft.summer.web.action.MemoryAction.execute(MemoryAction.java:</span><span style="color: #000000">102</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:</span><span style="color: #000000">106</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:</span><span style="color: #000000">430</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.thunisoft.fy.web.struts.SummerRequestProcessor.process(SummerRequestProcessor.java:</span><span style="color: #000000">134</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.struts.action.ActionServlet.process(ActionServlet.java:</span><span style="color: #000000">1196</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:</span><span style="color: #000000">414</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;javax.servlet.http.HttpServlet.service(HttpServlet.java:</span><span style="color: #000000">689</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;javax.servlet.http.HttpServlet.service(HttpServlet.java:</span><span style="color: #000000">802</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:</span><span style="color: #000000">237</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:</span><span style="color: #000000">157</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.thunisoft.summer.web.filter.UserAASFilter.doFilter(UserAASFilter.java:</span><span style="color: #000000">111</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:</span><span style="color: #000000">186</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:</span><span style="color: #000000">157</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.ajaxanywhere.AAFilter.doFilter(AAFilter.java:</span><span style="color: #000000">46</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:</span><span style="color: #000000">186</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:</span><span style="color: #000000">157</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.thunisoft.summer.web.filter.CharsetFilter.doFilter(CharsetFilter.java:</span><span style="color: #000000">48</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:</span><span style="color: #000000">186</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:</span><span style="color: #000000">157</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:</span><span style="color: #000000">214</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:</span><span style="color: #000000">104</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:</span><span style="color: #000000">520</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:</span><span style="color: #000000">198</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:</span><span style="color: #000000">152</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:</span><span style="color: #000000">104</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:</span><span style="color: #000000">520</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:</span><span style="color: #000000">137</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:</span><span style="color: #000000">104</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:</span><span style="color: #000000">118</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:</span><span style="color: #000000">102</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:</span><span style="color: #000000">520</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:</span><span style="color: #000000">109</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:</span><span style="color: #000000">104</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:</span><span style="color: #000000">520</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:</span><span style="color: #000000">929</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:</span><span style="color: #000000">160</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:</span><span style="color: #000000">799</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:</span><span style="color: #000000">705</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:</span><span style="color: #000000">577</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:</span><span style="color: #000000">683</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;java.lang.Thread.run(Thread.java:</span><span style="color: #000000">534</span><span style="color: #000000">)<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span></div>
&nbsp;&nbsp;&nbsp;&nbsp; 咨询同事，得到的是&#8220;增加静态方法&#8221;要重启tomcat服务。我重启了tomcat果然就没有问题了：）<br />
&nbsp;&nbsp;&nbsp;&nbsp; 有点不太明白，为什么增加静态方法就要重启tomcat服务？这样在开发过程中如果经常增加static方法岂不是每次都要重启，然后就会很浪费时间了。另外，为什么如果我只是修改了原来已经存在的static方法的实现，则可以正常调试。
<img src ="http://www.blogjava.net/midstr/aggbug/194488.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/midstr/" target="_blank">向左走向右走</a> 2008-04-21 12:54 <a href="http://www.blogjava.net/midstr/archive/2008/04/21/194488.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>开发中常用的几个eclipse插件</title><link>http://www.blogjava.net/midstr/archive/2008/03/16/186592.html</link><dc:creator>向左走向右走</dc:creator><author>向左走向右走</author><pubDate>Sun, 16 Mar 2008 04:20:00 GMT</pubDate><guid>http://www.blogjava.net/midstr/archive/2008/03/16/186592.html</guid><wfw:comment>http://www.blogjava.net/midstr/comments/186592.html</wfw:comment><comments>http://www.blogjava.net/midstr/archive/2008/03/16/186592.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/midstr/comments/commentRss/186592.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/midstr/services/trackbacks/186592.html</trackback:ping><description><![CDATA[<ol>
    <li><font style="background-color: #cce8cf">Myeclipse 主要用于eclipse的web开发，虽然它不是免费的，但我们一直在免费使用，因为网上的注册码太多了。</font>
    <li><font style="background-color: #cce8cf">Fatjar 一个易用的打包工具，会将编译用到的所有资源进行打包。如果是web项目打包，还是用myeclispe的export-&gt;WAR（EAR）</font>
    <li><font style="background-color: #cce8cf">Jode 反编译功能很好用。</font>
    <li>Hibernate Sychronizer（HibernateTools） 据说很好用。
    <li>JSEclipse（A<font style="background-color: #cce8cf">ptana</font>） 效果正在试用中。
    <li><font style="background-color: #cce8cf">PropertiesEditor</font> 属性文件编辑器&nbsp; <font style="background-color: #cce8cf"><a href="http://propedit.sourceforge.jp/eclipse/updates/">http://propedit.sourceforge.jp/eclipse/updates/</a></font>
    <li>SpringIDE&nbsp;&nbsp;&nbsp; <font style="background-color: #cce8cf"><a href="http://springide.org">http://springide.org</a></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://springide.org/updatesite/">http://springide.org/updatesite/</a>
    <li>EclEmma 最近才开始了解。</li>
</ol>
<img src ="http://www.blogjava.net/midstr/aggbug/186592.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/midstr/" target="_blank">向左走向右走</a> 2008-03-16 12:20 <a href="http://www.blogjava.net/midstr/archive/2008/03/16/186592.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java容器类分析zz</title><link>http://www.blogjava.net/midstr/archive/2007/08/14/136770.html</link><dc:creator>向左走向右走</dc:creator><author>向左走向右走</author><pubDate>Tue, 14 Aug 2007 11:56:00 GMT</pubDate><guid>http://www.blogjava.net/midstr/archive/2007/08/14/136770.html</guid><wfw:comment>http://www.blogjava.net/midstr/comments/136770.html</wfw:comment><comments>http://www.blogjava.net/midstr/archive/2007/08/14/136770.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/midstr/comments/commentRss/136770.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/midstr/services/trackbacks/136770.html</trackback:ping><description><![CDATA[<h2>Java容器类分析－数组（转载）</h2>
<div class=t_msgfont id=postmessage_2891>数组是Java语言内置的类型，除此之外，Java有多种保存对象引用的方式。Java类库提供了一套相当完整的容器类，使用这些类的方法可以保存和操纵对象。下面分别进行讨论，在研究Java容器类之前，先了解一下Java数组的基本功能和<span class=t_tag onclick=tagshow(event) href="tag.php?name=%CC%D8%D0%D4">特性</span>。<br><br>1.&nbsp;&nbsp;数组的基本特性<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;数组与其它种类的容器(List/Set/Map)之间的区别在于效率、确定的类型和保存基本类型<span class=t_tag onclick=tagshow(event) href="tag.php?name=%CA%FD%BE%DD">数据</span>的能力。数组是一种高效的存储和随机访问对象引用序列的方式，使用数组可以快速的访问数组中的元素。但是当创建一个数组对象(注意和对象数组的区别)后，数组的大小也就固定了，当数组空间不足的时候就再创建一个新的数组，把旧的数组中所有的引用<span class=t_tag onclick=tagshow(event) href="tag.php?name=%B8%B4%D6%C6">复制</span>到新的数组中。<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Java中的数组和容器都需要进行边界检查，如果越界就会得到一个RuntimeException异常。这点和C++中有所不同，C++中vector的操作符[]不会做边界检查，这在速度上会有一定的提高，Java的数组和容器会因为时刻存在的边界检查带来一些<span class=t_tag onclick=tagshow(event) href="tag.php?name=%D0%D4%C4%DC">性能</span>上的开销。<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Java中通用的容器类不会以具体的类型来处理对象，容器中的对象都是以Object类型处理的，这是Java中所有类的基类。另外，数组可以保存基本类型，而容器不能，它只能保存任意的Java对象。<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;一般情况下，考虑到效率与类型检查，应该尽可能考虑使用数组。如果要解决一般化的问题，数组可能会受到一些限制，这时可以使用Java提供的容器类。 <br><br>2.&nbsp;&nbsp;操作数组的实用功能<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;在java.util.Arrays类中，有许多static静态方法，提供了操作数组的一些基本功能：<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;equals()方法----用于比较两个数组是否相等，相等的条件是两个数组的元素个数必须相等，并且对应位置的元素也相等。<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;fill()方法----用以某个值填充整个数组，这个方法有点笨。<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;asList()方法----接受任意的数组为<span class=t_tag onclick=tagshow(event) href="tag.php?name=%B2%CE%CA%FD">参数</span>，将其转变为List容器。<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;binarySearch()方法----用于在已经排序的数组中查找元素，需要注意的是必须是已经排序过的数组。当Arrays.binarySearch()找到了查找目标时，该方法将返回一个等于或大于0的值，否则将返回一个负值，表示在该数组目前的排序状态下此目标元素所应该插入的位置。负值的计算公式是&#8220;-x-1&#8221;。x指的是第一个大于查找对象的元素在数组中的位置，如果数组中所有的元素都小于要查找的对象，则x = a.size()。如果数组中包含重复的元素，则无法保证找到的是哪一个元素，如果需要对没有重复元素的数组排序，可以使用TreeSet或者LinkedHashSet。另外，如果使用Comparator排序了某个对象数组，在使用该方法时必须提供同样的Comparator类型的参数。需要注意的是，基本类型数组无法使用Comparator进行排序。<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;sort()方法----对数组进行升序排序。<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;在Java标准类库中，另有static方法System.arraycopy()用来复制数组，它针对所有类型做了重载。<br><br><br>3.&nbsp;&nbsp;数组的排序<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;在Java1.0和1.1两个版本中，类库缺少基本的算法操作，包括排序的操作，Java2对此进行了改善。在进行排序的操作时，需要根据对象的实际类型执行比较操作，如果为每种不同的类型各自编写一个不同的排序方法，将会使得<span class=t_tag onclick=tagshow(event) href="tag.php?name=%B4%FA%C2%EB">代码</span>很难被复用。一般的程序<span class=t_tag onclick=tagshow(event) href="tag.php?name=%C9%E8%BC%C6">设计</span>目标应是&#8220;将保持不变的事物与会发改变的事物相分离&#8221;。在这里，不变的是通用的排序算法，变化的是各种对象相互比较的方式。<br><br>Java有两种方式来实现比较的功能，一种是实现java.lang.Comparable接口，该接口只有一个compareTo()方法，并以一个Object类为参数，如果当前对象小于参数则返回负值，如果相等返回零，如果当前对象大于参数则返回正值。另一种比较方法是采用策略(strategy)设计模式，将会发生变化的代码封装在它自己的类(策略对象)中，再将策略对象交给保持不变的代码中，后者使用此策略实现它的算法。因此，可以为不同的比较方式生成不同的对象，将它们用在同样的排序程序中。在此情况下，通过定义一个实现了Comparator接口的类而创建了一个策略，这个策略类有compare()和equals()两个方法，一般情况下实现compare()方法即可。<br><br>使用上述两种方法即可对任意基本类型的数组进行排序，也可以对任意的对象数组进行排序。再提示一遍，基本类型数组无法使用Comparator进行排序。<br><br>Java标准类库中的排序算法针对排序的类型进行了优化——针对基本类型设计了&#8220;快速排序&#8221;，针对对象设计的&#8220;稳定归并排序&#8221;。一般不用担心其性能。<br><br>
<h2>Java容器分析--List和Set</h2>
<div class=t_msgfont id=postmessage_2892>容器类可以大大提高编程效率和编程能力，在Java2中，所有的容器都由SUN公司的Joshua Bloch进行了重新设计，丰富了容器类库的功能。<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Java2容器类类库的用途是&#8220;保存对象&#8221;，它分为两类：<br><br>Collection----一组独立的元素，通常这些元素都服从某种规则。List必须保持元素特定的顺序，而Set不能有重复元素。<br><br>Map----一组成对的&#8220;键值对&#8221;对象，即其元素是成对的对象，最典型的应用就是数据字典，并且还有其它广泛的应用。另外，Map可以返回其所有键组成的Set和其所有值组成的Collection，或其键值对组成的Set，并且还可以像数组一样扩展多维Map，只要让Map中键值对的每个&#8220;值&#8221;是一个Map即可。<br><br>1.迭代器<br><br>&nbsp; &nbsp;&nbsp; &nbsp; 迭代器是一种设计模式，它是一个对象，它可以遍历并选择序列中的对象，而开发人员不需要了解该序列的底层结构。迭代器通常被称为&#8220;轻量级&#8221;对象，因为创建它的代价小。<br><br>&nbsp; &nbsp;&nbsp; &nbsp; Java中的Iterator功能比较简单，并且只能单向移动：<br><br>(1)&nbsp; &nbsp; 使用方法iterator()要求容器返回一个Iterator。第一次调用Iterator的next()方法时，它返回序列的第一个元素。<br><br>(2)&nbsp; &nbsp; 使用next()获得序列中的下一个元素。<br><br>(3)&nbsp; &nbsp; 使用hasNext()检查序列中是否还有元素。<br><br>(4)&nbsp; &nbsp; 使用remove()将迭代器新返回的元素删除。<br><br>Iterator是Java迭代器最简单的实现，为List设计的ListIterator具有更多的功能，它可以从两个方向遍历List，也可以从List中插入和删除元素。<br><br>2.List的功能方法<br><br>List(interface): 次序是List最重要的特点；它确保维护元素特定的顺序。List为Collection添加了许多方法，使得能够向List中间插入与移除元素(只推荐LinkedList使用)。一个List可以生成ListIterator，使用它可以从两个方向遍历List，也可以从List中间插入和删除元素。<br><br>ArrayList: 由数组实现的List。它允许对元素进行快速随机访问，但是向List中间插入与移除元素的速度很慢。ListIterator只应该用来由后向前遍历ArrayList，而不是用来插入和删除元素，因为这比LinkedList开销要大很多。<br><br>LinkedList: 对顺序访问进行了优化，向List中间插入与删除得开销不大，随机访问则相对较慢(可用ArrayList代替)。它具有方法addFirst()、addLast()、getFirst()、getLast()、removeFirst()、removeLast()，这些方法(没有在任何接口或基类中定义过)使得LinkedList可以当作堆栈、队列和双向队列使用。<br><br>3.Set的功能方法<br><br>Set(interface): 存入Set的每个元素必须是唯一的，因为Set不保存重复元素。加入Set的Object必须定义equals()方法以确保对象的唯一性。Set与Collection有完全一样的接口。Set接口不保证维护元素的次序。<br><br>HashSet: 为快速查找而设计的Set。存入HashSet的对象必须定义hashCode()。<br><br>TreeSet: 保持次序的Set，底层为树结构。使用它可以从Set中提取有序的序列。<br><br>LinkedHashSet: 具有HashSet的查询速度，且内部使用链表维护元素的顺序(插入的次序)。于是在使用迭代器遍历Set时，结果会按元素插入的次序显示。<br><br>&nbsp; &nbsp;&nbsp; &nbsp; HashSet采用散列函数对元素进行排序，这是专门为快速查询而设计的；TreeSet采用红黑树的数据结构进行排序元素；LinkedHashSet内部使用散列以加快查询速度，同时使用链表维护元素的次序，使得看起来元素是以插入的顺序保存的。需要注意的是，生成自己的类时，Set需要维护元素的存储顺序，因此要实现Comparable接口并定义compareTo()方法。</div>
<br><br><br>
<h2>Java容器分析--Map</h2>
<div class=t_msgfont id=postmessage_2893>标准的Java类库中包含了几种类型的Map，它们都拥有同样的基本接口Map，但是行为特性各不相同，主要表现在效率、键值对的保存、元素呈现次序、对象的保存周期和判定键是否等价的策略等方面。<br><br>1.Map的功能方法<br><br>Map(interface): 维护label和value的关联性，使得可以通过label查找value。<br><br>HashMap: Map基于散列表的实现，取代了Hashtable。插入和查询label/value的开销是固定的，并且可以通过构造器设置容量和负载因子，以调整容器的性能。<br><br>LinkedHashMap: 在HashMap的基础上做了一些改进，在迭代遍历它时，取得label/value的顺序是其插入的次序，或者是最近最少使用(LRU)的次序，速度上比HashMap要慢一点，但在迭代访问时速度会更快，主要原因是它使用了链表维护内部次序。<br><br>TreeMap: 查看label或label/value时，元素会被排序，其次序由Comparable或Comparator决定，因此查询所得到的结果是经过排序的。另外，它是唯一带有subMap()方法的Map具体类，即返回一个子树。它也是SortedMap接口的唯一实现，subMap()方法也是从该接口继承的。<br><br>WeakHashMap: Weak Key映射，允许释放映射所指向的对象。当映射之外没有引用指向某个label时，此label可以被垃圾收集器回收。<br><br>IdentityHashMap: 使用==代替equals()对label进行比较的散列映射。<br><br>2.hashCode()<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;当使用标准库中的类Integer作为HashMap的label时，程序能够正常运行，但是使用自己创建的类作为HashMap的label时，通常犯一个错误。<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;在HashMap中通过label查找value时，实际上是计算label对象地址的散列码来确定value的。一般情况下，我们是使用基类Object的方法hashCode()来生成散列码，它默认是使用对象的地址来计算的，因此由第一个对象new Apple(5)和第二个对象new Apple(5)生成的散列码是不同的，不能完成正确的查找。通常，我们可以编写自己的hashCode()方法来覆盖基类的原始方法，但与此同时，我们必须同时实现equals()方法来判断当前的label是否与表中存在的label相同。正确的equals()方法满足五个条件：<br><br>(1)&nbsp; &nbsp;&nbsp;&nbsp;自反性。对于任意的x，x.equals(x)一定返回true。<br><br>(2)&nbsp; &nbsp;&nbsp;&nbsp;对称性。对于任意的x和y，如果y.equals(x)返回true，则x.equals(y)也返回true。<br><br>(3)&nbsp; &nbsp;&nbsp;&nbsp;传递性。对于任意的x、y、z，如果有x.equals(y)返回true，y.equals(z)返回true，则x.equals(z)一定返回true。<br><br>(4)&nbsp; &nbsp;&nbsp;&nbsp;一致性。对于任意的x和y，如果对象中用于等价比较的信息没有改变，那么无论调用x.equals(y)多少次，返回的结果应该保持一致，要么一直是true，要么一直是false。<br><br>(5)&nbsp; &nbsp;&nbsp;&nbsp;对任何不是null的x，x.equals(null)一定返回false。<br><br>equals()比较的是对象的地址，如果要使用自己的类作为HashMap的label，必须同时重载hashCode()和equals()方法。<br><br>使用散列的目的：想要使用一个对象来查找另一个对象。使用TreeSet或TreeMap也能实现此目的。另外，还可以自己实现一个Map，此时，必须提供Map.entrySet()方法来生成Map.Entry对象的Set。<br><br>使用散列的价值：速度，散列使得查询可以快速进行。散列将label保存载数组中方便快速查询，因为存储一组元素最快的数据结构是数组，用它来表示label的信息(后面有信息的描述)，而不是label本身。通过label对象计算得到一个数字，作为数组的下标，这个数字就是散列码(即前面所述的信息)。该散列码具体是通过定义在基类Object中，可能由程序员自定义的类覆盖的hashCode()方法，即散列函数生成。为了解决数组容量带来的限制，可以使不同的label生成相同的下标，保存在一个链表list中，每一个链表就是数组的一个元素。查询label时就可以通过对list中的信息进行查找，当散列函数比较好，数组的每个位置中的list长度较短，则可以快速查找到数组元素list中的某个位置，提高了整体速度。<br><br>散列表中的slot通常称为bucket，为了使散列分步均匀，bucket的值一般取质数。但事实证明，质数实际上并不是散列bucket的理想容量，近来Java散列实现都使用2的幂，具体如何验证以后再续。<br><br>3.HashMap的性能因子<br><br>容量(capacity): 散列表中bucket的数量。<br><br>初始化容量(initial capacity): 创建散列表时bucket的数量。可以在构造方法中指定HashMap和HashSet的初始化容量。<br><br>尺寸(size): 散列表中记录的数量。(数组的元素个数，非list中元素总和)<br><br>负载因子(load factor): 尺寸/容量。负载因子为0，表示空的散列表，0.5表示半满的散列表。轻负载的散列表具有冲突少，适宜插入与查询的特点，但是使用迭代器遍历会比较慢。较高的负载会减少所需空间大小。当负载达到指定值时，容器会自动成倍地增加容量，并将原有的对象重新分配，存入新的bucket中，这个过程称为&#8220;重散列&#8221;。<br><br>4.重写hashCode()的关键<br><br>(1)&nbsp; &nbsp;&nbsp;&nbsp;对同一个对象调用hashCode()都应该生成同样的值。<br><br>(2)&nbsp; &nbsp;&nbsp;&nbsp;hashCode()方法不要依赖于对象中易变的数据，当数据发生变化时，hashCode()就会生成一个不同的散列码，即产生了一个不同的label。<br><br>(3)&nbsp; &nbsp;&nbsp;&nbsp;hashCode()不应依赖于具有唯一性的对象信息，例如对象地址。<br><br>(4)&nbsp; &nbsp;&nbsp;&nbsp;散列码应该更关心速度，而不是唯一性，因为散列码不必是唯一的。<br><br>(5)&nbsp; &nbsp;&nbsp;&nbsp;好的hashCode()应该产生分步均匀的散列码。在Effective Java(Addison-Wesley 2001)中，Joshua Bloch给hashCode()给出了设计指导，可以参考。<br><br>编写正确高效的hashCode()和equals()可以参考Apache的Jakarta Commons项目中的工具。</div>
<br></div><img src ="http://www.blogjava.net/midstr/aggbug/136770.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/midstr/" target="_blank">向左走向右走</a> 2007-08-14 19:56 <a href="http://www.blogjava.net/midstr/archive/2007/08/14/136770.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>处理 Java 程序中的内存漏洞zz</title><link>http://www.blogjava.net/midstr/archive/2007/08/13/136528.html</link><dc:creator>向左走向右走</dc:creator><author>向左走向右走</author><pubDate>Mon, 13 Aug 2007 15:12:00 GMT</pubDate><guid>http://www.blogjava.net/midstr/archive/2007/08/13/136528.html</guid><wfw:comment>http://www.blogjava.net/midstr/comments/136528.html</wfw:comment><comments>http://www.blogjava.net/midstr/archive/2007/08/13/136528.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/midstr/comments/commentRss/136528.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/midstr/services/trackbacks/136528.html</trackback:ping><description><![CDATA[&nbsp;原文：<a href="http://www.ibm.com/developerworks/cn/java/j-leaks/">http://www.ibm.com/developerworks/cn/java/j-leaks/</a><br><br>
<table cellSpacing=0 cellPadding=0 width="100%" border=0>
    <tbody>
        <tr vAlign=top>
            <td width="100%">
            <h1>处理 Java 程序中的内存漏洞</h1>
            <p id=subtitle>研究何时应该关注内存漏洞以及如何预防内存漏洞</p>
            <img class=display-img height=6 alt="" src="http://www.ibm.com/i/c.gif" width=1></td>
            <td class=no-print width=192><img height=18 alt=developerWorks src="http://www.ibm.com/developerworks/i/dw.gif" width=192></td>
        </tr>
    </tbody>
</table>
<table cellSpacing=0 cellPadding=0 width="100%" border=0>
    <tbody>
        <tr vAlign=top>
            <td width=10><img height=1 alt="" src="http://www.ibm.com/i/c.gif" width=10></td>
            <td width="100%">
            <table class=no-print cellSpacing=0 cellPadding=0 width=160 align=right border=0>
                <tbody>
                    <tr>
                        <td width=10><img height=1 alt="" src="http://www.ibm.com/i/c.gif" width=10></td>
                        <td>
                        <table cellSpacing=0 cellPadding=0 width=150 border=0>
                            <tbody>
                                <tr>
                                    <td class=v14-header-1-small>文档选项</td>
                                </tr>
                            </tbody>
                        </table>
                        <table class=v14-gray-table-border cellSpacing=0 cellPadding=0 border=0>
                            <tbody>
                                <tr>
                                    <td class=no-padding width=150>
                                    <table cellSpacing=0 cellPadding=0 width=143 border=0>
                                        <img height=1 alt="" src="http://www.ibm.com/i/c.gif" width=8>
                                        <form name=email action=https://www.ibm.com/developerworks/secure/email-it.jsp>
                                            <input type=hidden value="Java 程序中也有内存漏洞？当然有。与流行的观念相反，在 Java 编程中，内存管理仍然是需要考虑的问题。在本文中，您将了解到什么会导致内存漏洞以及何时应该关注这些漏洞。您还有机会实践一下在您自己的项目中解决漏洞问题。" name=body><input type=hidden value="处理 Java 程序中的内存漏洞" name=subject><input type=hidden value=cn name=lang>                                             <tbody>
                                                <tr vAlign=top>
                                                    <td width=8><img height=1 alt="" src="http://www.ibm.com/i/c.gif" width=8></td>
                                                    <td width=16><img height=16 alt=将此页作为电子邮件发送 src="http://www.ibm.com/i/v14/icons/em.gif" width=16 vspace=3></td>
                                                    <td width=122>
                                                    <p><a class=smallplainlink href="javascript:document.email.submit();"><strong><font color=#5c81a7 size=2>将此页作为电子邮件发送</font></strong></a></p>
                                                    </td>
                                                </tr>
                                                <noscript>
                                                <tr valign="top">
                                                    <td width="8"><img alt="" height="1" width="8" src="//www.ibm.com/i/c.gif"/></td>
                                                    <td width="16"><img alt="" width="16" height="16" src="//www.ibm.com/i/c.gif"/></td>
                                                    <td class="small" width="122">
                                                    <p><span class="ast">未显示需要 JavaScript 的文档选项</span></p>
                                                    </td>
                                                </tr>
                                                </noscript>
                                            </form>
                                        </tbody>
                                    </table>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <!--start RESERVED FOR FUTURE USE INCLUDE FILES--><!-- this content will be automatically generated across all content areas --><br><!--end RESERVED FOR FUTURE USE INCLUDE FILES--><br></td>
                    </tr>
                </tbody>
            </table>
            <p>级别： 初级</p>
            <p><a href="http://www.ibm.com/developerworks/cn/java/j-leaks/#author"><font color=#996699>Jim Patrick</font></a> (<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#112;&#97;&#116;&#114;&#105;&#99;&#107;&#106;&#64;&#117;&#115;&#46;&#105;&#98;&#109;&#46;&#99;&#111;&#109;&#63;&#115;&#117;&#98;&#106;&#101;&#99;&#116;&#61;&#22788;&#29702;&#32;&#74;&#97;&#118;&#97;&#32;&#31243;&#24207;&#20013;&#30340;&#20869;&#23384;&#28431;&#27934;&#38;&#97;&#109;&#112;&#59;&#97;&#109;&#112;&#59;&#97;&#109;&#112;&#59;&#97;&#109;&#112;&#59;&#99;&#99;&#61;&#112;&#97;&#116;&#114;&#105;&#99;&#107;&#106;&#64;&#117;&#115;&#46;&#105;&#98;&#109;&#46;&#99;&#111;&#109;"><font color=#5c81a7>patrickj@us.ibm.com</font></a>), 顾问程序员, IBM Pervasive Computing<br></p>
            <p>2001 年 2 月 01 日</p>
            <blockquote>Java 程序中也有内存漏洞？当然有。与流行的观念相反，在 Java 编程中，内存管理仍然是需要考虑的问题。在本文中，您将了解到什么会导致内存漏洞以及何时应该关注这些漏洞。您还有机会实践一下在您自己的项目中解决漏洞问题。</blockquote><!--start RESERVED FOR FUTURE USE INCLUDE FILES--><!-- include java script once we verify teams wants to use this and it will work on dbcs and cyrillic characters --><!--end RESERVED FOR FUTURE USE INCLUDE FILES-->
            <p><a name=1a><span class=atitle>Java 程序中的内存漏洞是如何显现出来的</span></a></p>
            <p>大多数程序员都知道，使用像 Java 这样的编程语言的一大好处就是，他们不必再担心内存的分配和释放问题。您只须创建对象，当应用程序不再需要这些对象时，Java 会通过一种称为&#8220;垃圾收集&#8221;的机制将这些对象删除。这种处理意味着 Java 已经解决了困扰其他编程语言的烦人问题 -- 可怕的内存漏洞。是这样的吗？</p>
            <p>在深入讨论之前，我们先回顾一下垃圾收集的工作方式。垃圾收集器的工作是发现应用程序不再需要的对象，并在这些对象不再被访问或引用时将它们删除。垃圾收集器从根节点（在 Java 应用程序的整个生存周期内始终存在的那些类）开始，遍历被引用的所有节点进行清除。在它遍历这些节点的同时，它跟踪哪些对象当前正被引用着。任何类只要不再被引用，它就符合垃圾收集的条件。当删除这些对象以后，就可将它们所占用的内存资源返回给 Java 虚拟机 (JVM)。</p>
            <p>所以的确是这样，Java 代码不要求程序员负责内存的管理和清除，它会自动对无用的对象执行垃圾收集。但是，要紧记的一点是 <em>仅当一个对象不再被引用时才会被统计为无用的</em> 。图 1 说明了这个概念。 </p>
            <br><a name=N10055><strong>图 1. 无用但仍被引用的对象</strong></a><br><img height=288 alt=无用但仍被引用的对象 src="http://www.ibm.com/developerworks/cn/java/j-leaks/classrefr.gif" width=441 border=0> <br>
            <p>上面说明了在 Java 应用程序执行期间具有不同生存周期的两个类。类 <code>A</code> 首先被实例化，并会在很长一段时间或程序的整个生存期内存在。在某个时候，类 <code>B</code> 被创建，类 <code>A</code> 添加对这个新创建的类的一个引用。现在，我们假定类 <code>B</code> 是某个用户界面小部件，它由用户显示甚至解除。如果没有清除类 <code>A</code> 对 <code>B</code> 的引用，则即便不再需要类 <code>B</code> ，并且即便在执行下一个垃圾收集周期以后，类 <code>B</code> 仍将存在并占用内存空间。 </p>
            <br>
            <table cellSpacing=0 cellPadding=0 width="100%" border=0>
                <tbody>
                    <tr>
                        <td><img height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"><br><img height=6 alt="" src="http://www.ibm.com/i/c.gif" width=8 border=0></td>
                    </tr>
                </tbody>
            </table>
            <table class=no-print cellSpacing=0 cellPadding=0 align=right>
                <tbody>
                    <tr align=right>
                        <td><img height=4 alt="" src="http://www.ibm.com/i/c.gif" width="100%"><br>
                        <table cellSpacing=0 cellPadding=0 border=0>
                            <tbody>
                                <tr>
                                    <td vAlign=center><img height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><br></td>
                                    <td vAlign=top align=right><a class=fbox href="http://www.ibm.com/developerworks/cn/java/j-leaks/#main"><strong><font color=#996699>回页首</font></strong></a></td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br><br>
            <p><a name=1><span class=atitle>何时应该关注内存漏洞？</span></a></p>
            <p>如果您的程序在执行一段时间以后发出 <code>java.lang.OutOfMemoryError</code> 错误，则内存漏洞肯定是一个重大嫌疑。除了这种明显的情况之外，何时还应该关注内存漏洞呢？持完美主义观点的程序员肯定会回答，应该查找并纠正 <em>所有</em>内存漏洞。但是，在得出这个结论之前，还有几个方面需要考虑，包括程序的生存期和漏洞的大小。 </p>
            <p>完全有这样的可能，垃圾收集器在应用程序的生存期内可能始终不会运行。不能保证 JVM 何时以及是否会调用垃圾收集器 -- 即便程序显式地调用 <code>System.gc()</code> 也是如此。通常，在当前的可用内存能够满足程序的内存需求时，JVM 不会自动运行垃圾收集器。当可用内存不能满足需求时，JVM 将首先尝试通过调用垃圾收集来释放出更多的可用内存。如果这种尝试仍然不能释放足够的资源，JVM 将从操作系统获取更多的内存，直至达到允许的最大极限。 </p>
            <p>例如，考虑一个小型 Java 应用程序，它显示一些用于修改配置的简单用户界面元素，并且它有一个内存漏洞。很可能到应用程序关闭时也不会调用垃圾收集器，因为 JVM 很可能有足够的内存来创建程序所需的全部对象，而此后可用内存则所剩无几。因此，在这种情况下，即使某些&#8220;死&#8221;对象在程序执行时占用着内存，它实际上并没有什么用途。</p>
            <p>如果正在开发的 Java 代码要全天 24 小时在服务器上运行，则内存漏洞在此处的影响就比在我们的配置实用程序中的影响要大得多。在要长时间运行的某些代码中，即使最小的漏洞也会导致 JVM 耗尽全部可用内存。</p>
            <p>在相反的情况下，即便程序的生存期较短，如果存在分配大量临时对象（或者若干吞噬大量内存的对象）的任何 Java 代码，而且当不再需要这些对象时也没有取消对它们的引用，则仍然可能达到内存极限。</p>
            <p>最后一种情况是内存漏洞无关紧要。我们不应该认为 Java 内存漏洞像其他语言（如 C++）中的漏洞那样危险，在那些语言中内存将丢失，且永远不会被返回给操作系统。在 Java 应用程序中，我们使不需要的对象依附于操作系统为 JVM 所提供的内存资源。所以从理论上讲，一旦关闭 Java 应用程序及其 JVM，所分配的全部内存将被返回给操作系统。</p>
            <br>
            <table cellSpacing=0 cellPadding=0 width="100%" border=0>
                <tbody>
                    <tr>
                        <td><img height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"><br><img height=6 alt="" src="http://www.ibm.com/i/c.gif" width=8 border=0></td>
                    </tr>
                </tbody>
            </table>
            <table class=no-print cellSpacing=0 cellPadding=0 align=right>
                <tbody>
                    <tr align=right>
                        <td><img height=4 alt="" src="http://www.ibm.com/i/c.gif" width="100%"><br>
                        <table cellSpacing=0 cellPadding=0 border=0>
                            <tbody>
                                <tr>
                                    <td vAlign=center><img height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><br></td>
                                    <td vAlign=top align=right><a class=fbox href="http://www.ibm.com/developerworks/cn/java/j-leaks/#main"><strong><font color=#996699>回页首</font></strong></a></td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br><br>
            <p><a name=2><span class=atitle>确定应用程序是否有内存漏洞</span></a></p>
            <p>为了查看在 Windows NT 平台上运行的某个 Java 应用程序是否有内存漏洞，您可能试图在应用程序运行时观察&#8220;任务管理器&#8221;中的内存设置。但是，在观察了运行中的几个 Java 应用程序以后，您会发现它们比本地应用程序占用的内存要多得多。我做过的一些 Java 项目要使用 10 到 20 MB 的系统内存才能启动。而操作系统自带的 Windows Explorer 程序只需 5 MB 左右的内存。</p>
            <p>在 Java 应用程序内存使用方面应注意的另一点是，这个典型程序在 IBM JDK 1.1.8 JVM 中运行时占用的系统内存越来越多。似乎直到为它分配非常多的物理内存以后它才开始向系统返回内存。这些情况是内存漏洞的征兆吗？</p>
            <p>要理解其中的缘由，我们必须熟悉 JVM 如何将系统内存用作它的堆。当运行 <code>java.exe</code> 时，您使用一定的选项来控制垃圾收集堆的起始大小和最大大小（分别用 -ms 和 -mx 表示）。Sun JDK 1.1.8 的默认起始设置为 1 MB，默认最大设置为 16 MB。IBM JDK 1.1.8 的默认最大设置为系统总物理内存大小的一半。这些内存设置对 JVM 在用尽内存时所执行的操作有直接影响。JVM 可能继续增大堆，而不等待一个垃圾收集周期的完成。 </p>
            <p>这样，为了查找并最终消除内存漏洞，我们需要使用比任务监视实用程序更好的工具。当您试图调试内存漏洞时，内存调试程序（请参阅 <a href="http://www.ibm.com/developerworks/cn/java/j-leaks/#resources"><font color=#996699>参考资源</font></a>）可能派得上用场。这些程序通常会显示堆中的对象数、每个对象的实例数和这些对象所占用的内存等信息。此外，它们也可能提供有用的视图，这些视图可以显示每个对象的引用和引用者，以便您跟踪内存漏洞的来源。 </p>
            <p>下面我将说明我是如何用 Sitraka Software 的 JProbedebugger 检测和去除内存漏洞的，以使您对这些工具的部署方式以及成功去除漏洞所需的过程有所了解。</p>
            <br>
            <table cellSpacing=0 cellPadding=0 width="100%" border=0>
                <tbody>
                    <tr>
                        <td><img height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"><br><img height=6 alt="" src="http://www.ibm.com/i/c.gif" width=8 border=0></td>
                    </tr>
                </tbody>
            </table>
            <table class=no-print cellSpacing=0 cellPadding=0 align=right>
                <tbody>
                    <tr align=right>
                        <td><img height=4 alt="" src="http://www.ibm.com/i/c.gif" width="100%"><br>
                        <table cellSpacing=0 cellPadding=0 border=0>
                            <tbody>
                                <tr>
                                    <td vAlign=center><img height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><br></td>
                                    <td vAlign=top align=right><a class=fbox href="http://www.ibm.com/developerworks/cn/java/j-leaks/#main"><strong><font color=#996699>回页首</font></strong></a></td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br><br>
            <p><a name=3><span class=atitle>内存漏洞的一个示例</span></a></p>
            <p>本例集中讨论一个问题，我们部门当时正在开发一个商业发行版软件，这是一个 Java JDK 1.1.8 应用程序，一个测试人员花了几个小时研究这个程序才最终使这个问题显现出来。这个 Java 应用程序的基本代码和包是由几个不同的开发小组在不同的时间开发的。我猜想，该应用程序中意外出现的内存漏洞是由那些没有真正理解别人开发的代码的程序员造成的。 </p>
            <p>我们正在讨论的 Java 代码允许用户为 Palm 个人数字助理创建应用程序，而不必编写任何 Palm OS 本地代码。通过使用图形用户界面，用户可以创建窗体，向窗体中添加控件，然后连接这些控件的事件来创建 Palm 应用程序。测试人员发现，随着不断创建和删除窗体和控件，这个 Java 应用程序最终会耗尽内存。开发人员没有检测到这个问题，因为他们的机器有更多的物理内存。</p>
            <p>为了研究这个问题，我用 JProbe 来确定什么地方出了差错。尽管用了 JProbe 所提供的强大工具和内存快照，研究仍然是一个冗长乏味、不断重复的过程，首先要确定出现内存漏洞的原因，然后修改代码，最后还得检验结果。</p>
            <p>JProbe 提供几个选项，用来控制调试期间实际记录哪些信息。经过几次试验以后，我断定获取所需信息的最有效方法是，关闭性能数据收集，而将注意力集中在所捕获的堆数据上。JProbe 提供了一个称为 Runtime Heap Summary 的视图，它显示 Java 应用程序运行时所占用的堆内存量随时间的变化。它还提供了一个工具栏按钮，必要时可以强制 JVM 执行垃圾收集。如果您试图弄清楚，当 Java 应用程序不再需要给定的类实例时，这个实例会不会被作为垃圾收集，这个功能将很有用。图 2 显示了使用中的堆存储量随时间的变化。</p>
            <br><a name=N100DC><strong>图 2. Runtime Heap Summary</strong></a><br><img height=427 alt="Runtime Heap Summary" src="http://www.ibm.com/developerworks/cn/java/j-leaks/heapsummary.gif" width=479 border=0> <br>
            <p>在 Heap Usage Chart 中，蓝色部分表明已分配的堆空间大小。在启动这个 Java 程序并达到稳定状态以后，我强制垃圾收集器运行，在图中的表现就是绿线（这条线表明插入了一个检查点）左侧的蓝线的骤降。随后，我添加了四个窗体，然后又将它们删除，并再次调用了垃圾收集器。当程序返回仅有一个可视窗体的初始状态时，检查点之后的蓝色区域高于检查点之前的蓝色区域这一情况表明可能存在内存漏洞。我通过查看 Instance Summary 证实确实有一个漏洞，因为 Instance Summary 表明 <code>FormFrame</code> 类（它是窗体的主用户界面类）的计数在检查点之后增加了 4。 </p>
            <br>
            <table cellSpacing=0 cellPadding=0 width="100%" border=0>
                <tbody>
                    <tr>
                        <td><img height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"><br><img height=6 alt="" src="http://www.ibm.com/i/c.gif" width=8 border=0></td>
                    </tr>
                </tbody>
            </table>
            <table class=no-print cellSpacing=0 cellPadding=0 align=right>
                <tbody>
                    <tr align=right>
                        <td><img height=4 alt="" src="http://www.ibm.com/i/c.gif" width="100%"><br>
                        <table cellSpacing=0 cellPadding=0 border=0>
                            <tbody>
                                <tr>
                                    <td vAlign=center><img height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><br></td>
                                    <td vAlign=top align=right><a class=fbox href="http://www.ibm.com/developerworks/cn/java/j-leaks/#main"><strong><font color=#996699>回页首</font></strong></a></td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br><br>
            <p><a name=4><span class=atitle>查找原因</span></a></p>
            <p>为了将测试人员报告的问题剔出，我采取的第一个步骤是找出几个简单的、可重复的测试案例。就本例而言，我发现只须添加一个窗体，将它删除，然后强制执行垃圾收集，结果就会导致与被删除窗体相关联的许多类实例仍然处于活动状态。这个问题在 JProbe 的 Instance Summary 视图中很明显，这个视图统计每个 Java 类在堆中的实例数。 </p>
            <p>为了查明使垃圾收集器无法正常完成其工作的那些引用，我使用 JProbe 的 Reference Graph（如图 3 所示）来确定哪些类仍然引用着目前未被删除的 <code>FormFrame</code> 类。在调试这个问题时该过程是最复杂的过程之一，因为我发现许多不同的对象仍然引用着这个无用的对象。用来查明究竟是哪个引用者真正造成这个问题的试错过程相当耗时。 </p>
            <p>在本例中，一个根类（左上角用红色标明的那个类）是问题的发源地。右侧用蓝色突出显示的类处在从最初的 <code>FormFrame</code> 类跟踪而来的路径上。 </p>
            <br><a name=N1010C><strong>图 3. 在引用图中跟踪内存漏洞</strong></a><br><img height=340 alt=在引用图中跟踪内存漏洞 src="http://www.ibm.com/developerworks/cn/java/j-leaks/refgraph.gif" width=458 border=0> <br>
            <p>就本例而言，最后查明罪魁祸首是包含一个静态 hashtable 的字体管理器类。通过逆向追踪引用者列表，我发现根节点是用来存储每个窗体所用字体的一个静态 hashtable。各个窗体可被单独放大或缩小，所以这个 hashtable 包含一个具有某个给定窗体的全部字体的 vector。当窗体的大小改变时，就会提取这个字体 vector，并将适当的缩放因子应用于字体大小。</p>
            <p>这个字体管理器类的问题是，虽然程序在创建窗体时将字体 vector 存入这个 hashtable 中，但没有提供在删除窗体时删除 vector 的代码。因此，这个静态 hashtable（在应用程序的生存期内一直存在）永远不会删除引用每个窗体的那些键。结果，窗体及其所有关联的类都闲置在内存中。</p>
            <br>
            <table cellSpacing=0 cellPadding=0 width="100%" border=0>
                <tbody>
                    <tr>
                        <td><img height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"><br><img height=6 alt="" src="http://www.ibm.com/i/c.gif" width=8 border=0></td>
                    </tr>
                </tbody>
            </table>
            <table class=no-print cellSpacing=0 cellPadding=0 align=right>
                <tbody>
                    <tr align=right>
                        <td><img height=4 alt="" src="http://www.ibm.com/i/c.gif" width="100%"><br>
                        <table cellSpacing=0 cellPadding=0 border=0>
                            <tbody>
                                <tr>
                                    <td vAlign=center><img height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><br></td>
                                    <td vAlign=top align=right><a class=fbox href="http://www.ibm.com/developerworks/cn/java/j-leaks/#main"><strong><font color=#996699>回页首</font></strong></a></td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br><br>
            <p><a name=5><span class=atitle>修正</span></a></p>
            <p>本问题的一个简单解决方案是在字体管理器类中添加一个方法，以便在用户删除窗体时以适当的键作为参数调用 hashtable 的 <code>remove()</code> 方法。 <code>removeKeyFromHashtables()</code> 方法如下所示： </p>
            <table cellSpacing=0 cellPadding=0 width="100%" border=0>
                <tbody>
                    <tr>
                        <td class=code-outline>
                        <pre class=displaycode>public void removeKeyFromHashtables(GraphCanvas graph) {
                        if (graph != null) {
                        viewFontTable.remove(graph);     // 删除 hashtable 中的键
                        // 以预防内存漏洞
                        }
                        }
                        </pre>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br>
            <p>随后，我在 <code>FormFrame</code> 类中添加了一个对此方法的调用。 <code>FormFrame</code> 实际上是使用 Swing 的内部框架来实现窗体用户界面的，所以我将对字体管理器的调用添加到当完全关闭内部框架时所调用的方法中，如下所示： </p>
            <table cellSpacing=0 cellPadding=0 width="100%" border=0>
                <tbody>
                    <tr>
                        <td class=code-outline>
                        <pre class=displaycode>/**
                        * 当去掉 (dispose) FormFrame 时调用。清除引用以预防内存漏洞。
                        */
                        public void internalFrameClosed(InternalFrameEvent e) {
                        FontManager.get().removeKeyFromHashtables(canvas);
                        canvas = null;
                        setDesktopIcon(null);
                        }
                        </pre>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br>
            <p>当作了这些修改以后，我使用调试器证实：当执行相同的测试案例时，与被删除的窗体相关联的对象计数减小。</p>
            <br>
            <table cellSpacing=0 cellPadding=0 width="100%" border=0>
                <tbody>
                    <tr>
                        <td><img height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"><br><img height=6 alt="" src="http://www.ibm.com/i/c.gif" width=8 border=0></td>
                    </tr>
                </tbody>
            </table>
            <table class=no-print cellSpacing=0 cellPadding=0 align=right>
                <tbody>
                    <tr align=right>
                        <td><img height=4 alt="" src="http://www.ibm.com/i/c.gif" width="100%"><br>
                        <table cellSpacing=0 cellPadding=0 border=0>
                            <tbody>
                                <tr>
                                    <td vAlign=center><img height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><br></td>
                                    <td vAlign=top align=right><a class=fbox href="http://www.ibm.com/developerworks/cn/java/j-leaks/#main"><strong><font color=#996699>回页首</font></strong></a></td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br><br>
            <p><a name=6><span class=atitle>预防内存漏洞</span></a></p>
            <p>可以通过观察某些常见问题来预防内存漏洞。Collection 类（如 hashtable 和 vector）常常是出现内存漏洞的地方。当这个类被用 <code>static</code> 关键字声明并且在应用程序的整个生存期中存在时尤其是这样。 </p>
            <p>另一个常见的问题是，您将一个类注册为事件监听程序，而在不再需要这个类时没有撤销注册。此外，您常常需要在适当的时候将指向其他类的类成员变量设置为 null。</p>
            <br>
            <table cellSpacing=0 cellPadding=0 width="100%" border=0>
                <tbody>
                    <tr>
                        <td><img height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"><br><img height=6 alt="" src="http://www.ibm.com/i/c.gif" width=8 border=0></td>
                    </tr>
                </tbody>
            </table>
            <table class=no-print cellSpacing=0 cellPadding=0 align=right>
                <tbody>
                    <tr align=right>
                        <td><img height=4 alt="" src="http://www.ibm.com/i/c.gif" width="100%"><br>
                        <table cellSpacing=0 cellPadding=0 border=0>
                            <tbody>
                                <tr>
                                    <td vAlign=center><img height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><br></td>
                                    <td vAlign=top align=right><a class=fbox href="http://www.ibm.com/developerworks/cn/java/j-leaks/#main"><strong><font color=#996699>回页首</font></strong></a></td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br><br>
            <p><a name=7><span class=atitle>小结</span></a></p>
            <p>查找内存漏洞的原因可能是一个乏味的过程，更不用说需要专用调试工具的情况了。但是，一旦您熟悉了这些工具以及在跟踪对象引用时进行搜索的模式，您就能够找到内存漏洞。此外，您还会摸索出一些有价值的技巧，这些技巧不仅有助于节约项目的成本，而且使您能够领悟到在以后的项目中应该避免哪些编码方式来预防内存漏洞。 </p>
            <br><br>
            <p><a name=resources><span class=atitle>参考资料 </span></a></p>
            <p>在开始查找内存漏洞之前，请先熟悉下列一种调试器：</p>
            <ul>
                <li>您可以参阅本文在 developerWorks 全球站点上的 <a href="http://www.ibm.com/developerworks/library/j-leaks/index.html?S_TACT=105AGX52&amp;S_CMP=cn-a-j"><font color=#5c81a7>英文原文</font></a>. <br><br>
                <li>Intuitive System 的 <a href="http://www.optimizeit.com/"><font color=#5c81a7>Optimizeit Java Performance Profiler</font></a> <br><br>
                <li>Paul Moeller 的 <a href="http://www.geocities.com/moellep/debug/HeapInspector.html"><font color=#5c81a7>Win32Java Heap Inspector</font></a> <br><br>
                <li>IBM alphaWorks 网站上的 <a href="http://www.alphaworks.ibm.com/tech/jinsight"><font color=#5c81a7>Jinsight</font></a> <br></li>
            </ul>
            <p><a href="http://www.ibm.com/developerworks/library/jinsight/index.html?S_TACT=105AGX52&amp;S_CMP=cn-a-j"><font color=#5c81a7>Jinsight: A tool for visualizing the execution of Java programs</font></a> （developerWorks，1999 年 11 月）详细说明了这个实用程序是如何帮助您分析性能和调试代码的。 </p>
            <p><strong>注：</strong> 本文讨论的项目是用 JDK 1.1.8 完成的，但 JDK 1.2 引入了一个新包， <a href="http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ref/package-summary.html"><font color=#5c81a7><code>java.lang.ref</code> </font></a>，这个包可与垃圾收集器交互。另外，JDK 1.2 还引入了一个 <a href="http://java.sun.com/products/jdk/1.2/docs/api/java/util/WeakHashMap.html"><font color=#5c81a7><code>java.util.WeakHashMap</code> </font></a>类，可用它来代替传统的 <code>java.util.Hashtable</code> 类。这个类不会阻止垃圾收集器回收键对象。JDK 1.3 的 Solaris、Linux 和 Microsoft Windows 版本引入了 <a href="http://java.sun.com/products/hotspot/whitepaper.html"><font color=#5c81a7>Java HotSpot Client VM</font></a>，该虚拟机带有一个新的、经过改进的垃圾收集器。 </p>
            <br><br>
            <p><a name=author><span class=atitle>关于作者</span></a></p>
            <table cellSpacing=0 cellPadding=0 width="100%" border=0>
                <tbody>
                    <tr>
                        <td colSpan=3><img height=5 alt="" src="http://www.ibm.com/i/c.gif" width="100%"></td>
                    </tr>
                    <tr vAlign=top align=left>
                        <td>
                        <p>&nbsp;</p>
                        </td>
                        <td><img height=5 alt="" src="http://www.ibm.com/i/c.gif" width=4></td>
                        <td width="100%">
                        <p>Jim Patrick 是 IBM Pervasive Computing Division 的一名顾问程序员。他从 1996 年开始用 Java 编写程序。请通过 <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#112;&#97;&#116;&#114;&#105;&#99;&#107;&#106;&#64;&#117;&#115;&#46;&#105;&#98;&#109;&#46;&#99;&#111;&#109;&#63;&#99;&#99;&#61;&#112;&#97;&#116;&#114;&#105;&#99;&#107;&#106;&#64;&#117;&#115;&#46;&#105;&#98;&#109;&#46;&#99;&#111;&#109;"><font color=#5c81a7>patrickj@us.ibm.com</font></a> 与 Jim 联系。 </p>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table><img src ="http://www.blogjava.net/midstr/aggbug/136528.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/midstr/" target="_blank">向左走向右走</a> 2007-08-13 23:12 <a href="http://www.blogjava.net/midstr/archive/2007/08/13/136528.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>