﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-黑灵客栈-随笔分类-不编不知道，一编吓一跳</title><link>http://www.blogjava.net/mstar/category/1485.html</link><description>搞软件开发就像被强奸,如果不能反抗,就享受它吧！</description><language>zh-cn</language><lastBuildDate>Wed, 11 Aug 2010 03:46:05 GMT</lastBuildDate><pubDate>Wed, 11 Aug 2010 03:46:05 GMT</pubDate><ttl>60</ttl><item><title>Windows XP上给IIS注册WCF服务</title><link>http://www.blogjava.net/mstar/archive/2010/08/11/328481.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Wed, 11 Aug 2010 01:59:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2010/08/11/328481.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/328481.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2010/08/11/328481.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/328481.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/328481.html</trackback:ping><description><![CDATA[<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%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">C:\WINDOWS\Microsoft.NET\Framework\v2.</span><span style="color: #000000">0.50727</span><span style="color: #000000">&gt;</span><span style="color: #000000">aspnet_regiis.exe&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">i</span></div>
<br />
<br />
Start installing ASP.NET (2.0.50727).<br />
...<br />
Finished installing ASP.NET (2.0.50727).<br />
<br />
<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%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000">C:\WINDOWS\Microsoft.NET\Framework\v3.</span><span style="color: #000000">0</span><span style="color: #000000">\Windows&nbsp;Communication&nbsp;Foundation</span><span style="color: #000000">&gt;</span><span style="color: #000000">ServiceModelReg.exe&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">i&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">x</span></div>
<br />
<br />
Microsoft(R) Windows Communication Foundation Installation Utility<br />
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]<br />
Copyright (c) Microsoft Corporation.&nbsp; All rights reserved.<br />
<br />
<br />
Installing: Machine.config Section Groups and Handlers<br />
<br />
Installing: System.Web Build Provider<br />
<br />
Installing: System.Web Compilation Assemblies<br />
<br />
Installing: HTTP Handlers<br />
<br />
Installing: HTTP Modules<br />
<br />
Installing: Web Host Script Mappings<br />
<br />
Installing: WMI Classes<br />
<br />
Installing: Windows CardSpace (idsvc)<br />
<br />
Installing: Net.Tcp Port Sharing Service (NetTcpPortSharing)<br />
<br />
Installing: HTTP Namespace Reservations<br />
<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%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000">C:\WINDOWS\Microsoft.NET\Framework\v3.</span><span style="color: #000000">0</span><span style="color: #000000">\Windows&nbsp;Communication&nbsp;Foundation</span><span style="color: #000000">&gt;</span><span style="color: #000000">ServiceModelReg.exe&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">s:W3SVC</span></div>
<br />
Microsoft(R) Windows Communication Foundation Installation Utility<br />
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]<br />
Copyright (c) Microsoft Corporation.&nbsp; All rights reserved.<br />
<br />
Installing: Web Host Script Mappings<br />
<br />
3.<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%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000">C:\WINDOWS\Microsoft.NET\Framework\v3.</span><span style="color: #000000">5</span><span style="color: #000000">&gt;</span><span style="color: #000000">WFServicesReg.exe&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">c<br />
<br />
C:\WINDOWS\Microsoft.NET\Framework\v3.</span><span style="color: #000000">5</span><span style="color: #000000">&gt;</span><span style="color: #000000">WFServicesReg.exe&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">r</span></div>
<br />
4.&nbsp;&nbsp;发生<a id="viewpost_ascx_TitleUrl" title="Title of this entry." href="http://geekswithblogs.net/TimH/archive/2009/05/14/error-failed-to-access-iis-metabase.-hosting-wcf-service-in.aspx">Error: Failed to access IIS metabase</a><br />
<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">aspnet_regiis&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">ga&nbsp;ASPNET</span></div>
Start granting ASPNET access to the IIS metabase and other directories used by ASP.NET.<br />
Finished granting ASPNET access to the IIS metabase and other directories used by ASP.NET.
<img src ="http://www.blogjava.net/mstar/aggbug/328481.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2010-08-11 09:59 <a href="http://www.blogjava.net/mstar/archive/2010/08/11/328481.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle建完索引后要analyze一下才行!</title><link>http://www.blogjava.net/mstar/archive/2009/11/25/303667.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Wed, 25 Nov 2009 09:33:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2009/11/25/303667.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/303667.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2009/11/25/303667.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/303667.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/303667.html</trackback:ping><description><![CDATA[execute dbms_stats.gather_table_stats(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ownname=&gt;'BTA',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tabname=&gt;'BTAM003TB',<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; partname=&gt; NULL,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; estimate_percent=&gt;100,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cascade=&gt;TRUE,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; degree=&gt;1);
<img src ="http://www.blogjava.net/mstar/aggbug/303667.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2009-11-25 17:33 <a href="http://www.blogjava.net/mstar/archive/2009/11/25/303667.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Visual Studio开发QT程序--环境配置</title><link>http://www.blogjava.net/mstar/archive/2009/11/12/302152.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Thu, 12 Nov 2009 14:53:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2009/11/12/302152.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/302152.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2009/11/12/302152.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/302152.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/302152.html</trackback:ping><description><![CDATA[一. 下载QT. 设置系统变量 QT_HOME为Qt的根目录.例如:C:\Qt\2009.04\qt<br />
<br />
二. 安装VS.<br />
<br />
以上两步没啥好说的.<br />
<br />
三. 编译本地Qt库. 不然你会出现找不到qmaind.lib文件这样的编译错误.<br />
<br />
通过Visual Studio 2008 Command Prompt进入控制台.<br />
一定要通过这个. 不能在运行里直接输入cmd进入. 这样的话是没有VC编译环境的.<br />
<img src="http://www.blogjava.net/images/blogjava_net/mstar/pics2009/1.png" alt="" border="0" /><br />
<br />
在控制台里cd到QT目录, 目录里有个configure.exe<br />
输入: configure -platform win32-msvc<br />
需要一定的时间但来配置完成.<br />
<br />
然后输入: nmake<br />
然后要等很长时间等待Qt被编译成VC的lib格式.<br />
<br />
四. 创建项目<br />
在项目目录下:<br />
控制台输入: qmake -project<br />
然后: qmake -t vcapp -spec %QT_HOME%\mkspecs\win32-msvc2008<br />
spec后面的项目可以看mkspecs目录下的子目录. win32-msvc2005, win32-msvn2003什么的都有.<br />
<br />
然后就有VC的项目文件了.<br />
<br />
五. Visual Studio中的配置<br />
主要是qmake生成的项目配置中的qt路径有问题,所以要重新配置.<br />
主要是两项:<br />
1. include. 配置如下图:<br />
<img src="http://www.blogjava.net/images/blogjava_net/mstar/pics2009/2.png" alt="" border="0" /><br />
<br />
详细项目:<br />
<br />
<img src="http://www.blogjava.net/images/blogjava_net/mstar/pics2009/3.png" alt="" border="0" /><br />
<br />
<br />
2. linker 配置如下图:<br />
<img src="http://www.blogjava.net/images/blogjava_net/mstar/pics2009/4.png" alt="" border="0" /><br />
<br />
加载的lib详细项目<br />
<img src="http://www.blogjava.net/images/blogjava_net/mstar/pics2009/5.png" alt="" border="0" /><br />
<br />
这样就应该可以了.<br />
<br />
具体项目名称要看你编译出来的名字了. 我在我机器上编译出来的是QtGuid4.lib和QtCored4.lib<br />
另外要想运行编译出来的exe, 记得吧相关的dll文件复制到system32目录下.<br />
<br />
<img src ="http://www.blogjava.net/mstar/aggbug/302152.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2009-11-12 22:53 <a href="http://www.blogjava.net/mstar/archive/2009/11/12/302152.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Tomcat里的cpappend.bat </title><link>http://www.blogjava.net/mstar/archive/2009/11/05/301210.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Thu, 05 Nov 2009 01:43:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2009/11/05/301210.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/301210.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2009/11/05/301210.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/301210.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/301210.html</trackback:ping><description><![CDATA[在Tomcat的发行包中有一个bat文件很有意思.<br />
可以把指定的参数添加到classpath里面.<br />
和bat脚本for一起配合,可以实现自动的把某个目录下的jar包都放到classpath里.<br />
<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">rem&nbsp;</span><span style="color: #000000;">---------------------------------------------------------------------------</span><span style="color: #000000;"><br />
rem&nbsp;Append&nbsp;to&nbsp;CLASSPATH<br />
rem<br />
rem&nbsp;$Id:&nbsp;cpappend.bat&nbsp;</span><span style="color: #000000;">301115</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">2002</span><span style="color: #000000;">-</span><span style="color: #000000;">08</span><span style="color: #000000;">-</span><span style="color: #000000;">04</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">18</span><span style="color: #000000;">:</span><span style="color: #000000;">19</span><span style="color: #000000;">:43Z&nbsp;patrickl&nbsp;$<br />
rem&nbsp;</span><span style="color: #000000;">---------------------------------------------------------------------------</span><span style="color: #000000;"><br />
<br />
rem&nbsp;Process&nbsp;the&nbsp;first&nbsp;argument<br />
</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">""</span><span style="color: #000000;">%</span><span style="color: #000000;">1</span><span style="color: #000000;">""</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">""""</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">goto</span><span style="color: #000000;">&nbsp;end<br />
set&nbsp;CLASSPATH</span><span style="color: #000000;">=%</span><span style="color: #000000;">CLASSPATH</span><span style="color: #000000;">%</span><span style="color: #000000;">;</span><span style="color: #000000;">%</span><span style="color: #000000;">1</span><span style="color: #000000;"><br />
shift<br />
<br />
rem&nbsp;Process&nbsp;the&nbsp;remaining&nbsp;arguments<br />
:setArgs<br />
</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">""</span><span style="color: #000000;">%</span><span style="color: #000000;">1</span><span style="color: #000000;">""</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">""""</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">goto</span><span style="color: #000000;">&nbsp;doneSetArgs<br />
set&nbsp;CLASSPATH</span><span style="color: #000000;">=%</span><span style="color: #000000;">CLASSPATH</span><span style="color: #000000;">%</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">%</span><span style="color: #000000;">1</span><span style="color: #000000;"><br />
shift<br />
</span><span style="color: #0000ff;">goto</span><span style="color: #000000;">&nbsp;setArgs<br />
:doneSetArgs<br />
:end</span></div>
<br />
<strong>配合for一起用<br />
<br />
</strong>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">set&nbsp;CURRENT_DIR</span><span style="color: #000000;">=%</span><span style="color: #000000;">cd</span><span style="color: #000000;">%</span><span style="color: #000000;"><br />
set&nbsp;CLASSPATH</span><span style="color: #000000;">=</span><span style="color: #000000;">.<br />
</span><span style="color: #0000ff;">for</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">%%</span><span style="color: #000000;">i&nbsp;in&nbsp;(</span><span style="color: #000000;">%</span><span style="color: #000000;">CURRENT_DIR</span><span style="color: #000000;">%</span><span style="color: #000000;">\lib\</span><span style="color: #000000;">*</span><span style="color: #000000;">.jar)&nbsp;</span><span style="color: #0000ff;">do</span><span style="color: #000000;">&nbsp;call&nbsp;cpappend.bat&nbsp;</span><span style="color: #000000;">%%</span><span style="color: #000000;">i<br />
start&nbsp;java&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">Duser.dir</span><span style="color: #000000;">=%</span><span style="color: #000000;">CURRENT_DIR</span><span style="color: #000000;">%</span><span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">cp&nbsp;</span><span style="color: #000000;">%</span><span style="color: #000000;">CLASSPATH</span><span style="color: #000000;">%</span><span style="color: #000000;">&nbsp;a.b.c.MainApp</span></div>
<br />
<img src ="http://www.blogjava.net/mstar/aggbug/301210.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2009-11-05 09:43 <a href="http://www.blogjava.net/mstar/archive/2009/11/05/301210.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>判断一个类是另一个类的子类</title><link>http://www.blogjava.net/mstar/archive/2008/12/24/248076.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Wed, 24 Dec 2008 07:02:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2008/12/24/248076.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/248076.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2008/12/24/248076.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/248076.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/248076.html</trackback:ping><description><![CDATA[使用Class的isAssignableFrom方法可是实现。但是注意不要弄反了！<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> AssignableFromTest </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> TestCase {<br /><br />    </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> A {}<br />    </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> B </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> A{}<br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testIt(){<br />        A a </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> A();<br />        B b </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> B();<br />        assertTrue(a.getClass().isAssignableFrom(b.getClass()));<br />    }<br />}</span></div><br /><img src ="http://www.blogjava.net/mstar/aggbug/248076.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2008-12-24 15:02 <a href="http://www.blogjava.net/mstar/archive/2008/12/24/248076.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[待翻译]Categories of Java HotSpot VM Options</title><link>http://www.blogjava.net/mstar/archive/2007/12/26/Java_HotSpot_VM_Options.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Wed, 26 Dec 2007 06:23:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2007/12/26/Java_HotSpot_VM_Options.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/170579.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2007/12/26/Java_HotSpot_VM_Options.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/170579.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/170579.html</trackback:ping><description><![CDATA[
		<p class="intro">This document provides information on typical command-line options and environment variables that can affect the performance characteristics of the Java HotSpot Virtual Machine. Unless otherwise noted, all information in this document pertains to both the Java HotSpot Client VM and the Java HotSpot Server VM. <br /><br />Users of JDKs older than 1.3.0 who wish to port to a Java HotSpot VM, should see <a href="http://java.sun.com/javase/technologies/hotspot/exactoptions.jsp">Java HotSpot Equivalents of Exact VM flags</a>. </p>
		<span class="sp10"> </span>
		<br />
		<h3>Categories of Java HotSpot VM Options</h3>
		<span class="sp5"> </span>
		<br />
		<p>Standard options recognized by the Java HotSpot VM are described on the Java Application Launcher reference pages for <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html">Windows</a>, <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/java.html">Solaris</a> and <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/linux/java.html">Linux</a>. This document deals exclusively with non-standard options recognized by the Java HotSpot VM: </p>
		<ul>
				<li>Options that begin with <code>-X </code>are non-standard (not guaranteed to be supported on all VM implementations), and are subject to change without notice in subsequent releases of the JDK.</li>
				<li>Options that are specified with <code>-XX</code> are not stable and are not recommended for casual use. These options are subject to change without notice.</li>
		</ul>
		<span class="sp10"> </span>
		<br />
		<h3>Some Useful -XX Options</h3>
		<span class="sp5"> </span>
		<br />
		<p>Default values are listed for Java SE 6 for Solaris Sparc with -server. Some options may vary per architecture/OS/JVM version. Platforms with a differing default value are listed in the description. </p>
		<ul>
				<li>Boolean options are turned on with <code>-XX:+&lt;option&gt;</code> and turned off with <code>-XX:-&lt;option&gt;</code>.</li>
				<li>Numeric options are set with <code>-XX:&lt;option&gt;=&lt;number&gt;</code>. Numbers can include 'm' or 'M' for megabytes, 'k' or 'K' for kilobytes, and 'g' or 'G' for gigabytes (for example, 32k is the same as 32768).</li>
				<li>String options are set with <code>-XX:&lt;option&gt;=&lt;string&gt;</code>, are usually used to specify a file, a path, or a list of commands</li>
		</ul>
		<p>Flags marked as <i>manageable</i> are dynamically writeable through the JDK management interface (com.sun.management.HotSpotDiagnosticMXBean API) and also through JConsole. In <a href="http://java.sun.com/developer/technicalArticles/J2SE/monitoring/#Heap_Dump">Monitoring and Managing Java SE 6 Platform Applications</a>, Figure 3 shows an example. The manageable flags can also be set through <a href="http://java.sun.com/javase/6/docs/technotes/tools/share/jinfo.html">jinfo -flag</a>. <br /><br />The options below are loosely grouped into three categories. </p>
		<ul>
				<li>
						<a href="http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp#BehavioralOptions">Behavioral options</a> change the basic behavior of the VM. </li>
				<li>
						<a href="http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp#PerformanceTuning">Performance tuning</a> options are knobs which can be used to tune VM performance. </li>
				<li>
						<a href="http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp#DebuggingOptions">Debugging options</a> generally enable tracing, printing, or output of VM information.</li>
		</ul>
		<span class="sp10"> </span>
		<br />
		<hr class="light" />
		<h4>
				<a name="BehavioralOptions">
				</a>Behavioral Options</h4>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<th valign="top" align="left" width="45%">Option and Default Value<br /></th>
								<th valign="top" align="left" width="55%">Description</th>
						</tr>
						<tr valign="top">
								<td>-XX:-AllowUserSignalHandlers</td>
								<td>Do not complain if the application installs signal handlers. (Relevant to Solaris and Linux only.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:AltStackSize=16384</td>
								<td>Alternate signal stack size (in Kbytes). (Relevant to Solaris only, removed from 5.0.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:-DisableExplicitGC</td>
								<td>Disable calls to System.gc(), JVM still performs garbage collection when necessary.<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+FailOverToOldVerifier</td>
								<td>Fail over to old verifier when the new type checker fails. (Introduced in 6.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+HandlePromotionFailure</td>
								<td>The youngest generation collection does not require a guarantee of full promotion of all live objects. (Introduced in 1.4.2 update 11) [5.0 and earlier: false.]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+MaxFDLimit</td>
								<td>Bump the number of file descriptors to max. (Relevant  to Solaris only.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:PreBlockSpin=10</td>
								<td>Spin count variable for use with -XX:+UseSpinning. Controls the maximum spin iterations allowed before entering operating system thread synchronization code. (Introduced in 1.4.2.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:-RelaxAccessControlCheck</td>
								<td>Relax the access control checks in the verifier. (Introduced in 6.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+ScavengeBeforeFullGC</td>
								<td>Do young generation GC prior to a full GC. (Introduced in 1.4.1.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseAltSigs</td>
								<td>Use alternate signals instead of SIGUSR1 and SIGUSR2 for VM internal signals. (Introduced in 1.3.1 update 9, 1.4.1. Relevant to Solaris only.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseBoundThreads</td>
								<td>Bind user level threads to kernel threads. (Relevant to Solaris only.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:-UseConcMarkSweepGC</td>
								<td>Use concurrent mark-sweep collection for the old generation. (Introduced in 1.4.1)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseGCOverheadLimit</td>
								<td>Use a policy that limits the proportion of the VM's time that is spent in GC before an OutOfMemory error is thrown. (Introduced in 6.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseLWPSynchronization</td>
								<td>Use LWP-based instead of thread based synchronization. (Introduced in 1.4.0. Relevant to Solaris only.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:-UseParallelGC</td>
								<td>Use parallel garbage collection for scavenges. (Introduced in 1.4.1)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:-UseParallelOldGC</td>
								<td>Use parallel garbage collection for the full collections. Enabling this option automatically sets -XX:+UseParallelGC. (Introduced in 5.0 update 6.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:-UseSerialGC</td>
								<td>Use serial garbage collection. (Introduced in 5.0.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:-UseSpinning</td>
								<td>Enable naive spinning on Java monitor before entering operating system thread synchronizaton code. (Relevant to 1.4.2 and 5.0 only.) [1.4.2, multi-processor Windows platforms: true]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseTLAB</td>
								<td>Use thread-local object allocation (Introduced in 1.4.0, known as UseTLE prior to that.) [1.4.2 and earlier, x86 or with -client: false]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseSplitVerifier</td>
								<td>Use the new type checker with StackMapTable attributes. (Introduced in 5.0.)[5.0: false]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseThreadPriorities</td>
								<td>Use native thread priorities.<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseVMInterruptibleIO</td>
								<td>Thread interrupt before or with EINTR for I/O operations results in OS_INTRPT. (Introduced in 6. Relevant to Solaris only.)<br /><br /></td>
						</tr>
				</tbody>
		</table>
		<br />
		<a href="http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp#BehavioralOptions">
				<small>Back to Options</small>
		</a>
		<br />
		<span class="sp10"> </span>
		<br />
		<hr class="light" />
		<h4>
				<a name="PerformanceTuning">
				</a>Performance Options</h4>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<th valign="top" align="left" width="45%">Option and Default Value<br /></th>
								<th valign="top" align="left" width="55%">Description</th>
						</tr>
						<tr valign="top">
								<td>-XX:+AggressiveOpts</td>
								<td>Turn on point performance compiler optimizations that are expected to be default in upcoming releases. (Introduced in 5.0 update 6.)<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:CompileThreshold=10000</td>
								<td>Number of method invocations/branches before compiling [-client: 1,500]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:LargePageSizeInBytes=4m</td>
								<td>Sets the large page size used for the Java heap. (Introduced in 1.4.0 update 1.) [amd64: 2m.]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:MaxHeapFreeRatio=70</td>
								<td>Maximum percentage of heap free after GC to avoid shrinking.<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:MaxNewSize=size</td>
								<td>Maximum size of new generation (in bytes). Since 1.4, MaxNewSize is computed as a function of NewRatio. [1.3.1 Sparc: 32m; 1.3.1 x86: 2.5m.]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:MaxPermSize=64m</td>
								<td>Size of the Permanent Generation.  [5.0 and newer: 64 bit VMs are scaled 30% larger; 1.4 amd64: 96m; 1.3.1 -client: 32m.]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:MinHeapFreeRatio=40</td>
								<td>Minimum percentage of heap free after GC to avoid expansion.<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:NewRatio=2</td>
								<td>Ratio of new/old generation sizes. [Sparc -client: 8; x86 -server: 8; x86 -client: 12.]-client: 4 (1.3) 8 (1.3.1+), x86: 12]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:NewSize=2.125m</td>
								<td>Default size of new generation (in bytes) [5.0 and newer: 64 bit VMs are scaled 30% larger; x86: 1m; x86, 5.0 and older: 640k]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:ReservedCodeCacheSize=32m</td>
								<td>Reserved code cache size (in bytes) - maximum code cache size. [Solaris 64-bit, amd64, and -server x86: 48m; in 1.5.0_06 and earlier, Solaris 64-bit and and64: 1024m.]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:SurvivorRatio=8</td>
								<td>Ratio of eden/survivor space size [Solaris amd64: 6; Sparc in 1.3.1: 25; other Solaris platforms in 5.0 and earlier: 32]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:TargetSurvivorRatio=50</td>
								<td>Desired percentage of survivor space used after scavenge.<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:ThreadStackSize=512</td>
								<td>Thread Stack Size (in Kbytes). (0 means use default stack size) [Sparc: 512; Solaris x86: 320 (was 256 prior in 5.0 and earlier); Sparc 64 bit: 1024; Linux amd64: 1024 (was 0 in 5.0 and earlier); all others 0.]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseBiasedLocking</td>
								<td>Enable biased locking. For more details, see this <a href="http://java.sun.com/performance/reference/whitepapers/tuning.html#section4.2.5">tuning example</a>. (Introduced in 5.0 update 6.) [5.0: false]<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseFastAccessorMethods</td>
								<td>Use optimized versions of Get&lt;Primitive&gt;Field.<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:-UseISM</td>
								<td>Use Intimate Shared Memory. [Not accepted for non-Solaris platforms.] For details, see <a href="http://java.sun.com/docs/hotspot/ism.html">Intimate Shared Memory</a>.<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseLargePages</td>
								<td>Use large page memory. (Introduced in 5.0 update 5.) For details, see <a href="http://java.sun.com/javase/technologies/hotspot/largememory.jsp">Java Support for Large Memory Pages</a>.<br /><br /></td>
						</tr>
						<tr valign="top">
								<td>-XX:+UseMPSS</td>
								<td>Use Multiple Page Size Support w/4mb pages for the heap. Do not use with ISM as this replaces the need for ISM. (Introduced in 1.4.0 update 1, Relevant to Solaris 9 and newer.) [1.4.1 and earlier: false]<br /><br /></td>
						</tr>
				</tbody>
		</table>
		<br />
		<small>
				<a href="http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp#PerformanceTuning">
						<small>Back to Options</small>
				</a>
		</small>
		<br />
		<span class="sp10"> </span>
		<br />
		<hr class="light" />
		<h4>
				<a name="DebuggingOptions">Debugging Options</a>
		</h4>
		<br />
		<span class="sp10">
				<table cellspacing="0" cellpadding="0" width="100%" border="0">
						<tbody>
								<tr valign="top">
										<th valign="top" align="left" width="45%">Option and Default Value<br /></th>
										<th valign="top" align="left" width="55%">Description</th>
								</tr>
								<tr valign="top">
										<td>-XX:-CITime</td>
										<td>Prints time spent in JIT Compiler. (Introduced in 1.4.0.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:ErrorFile=./hs_err_pid&lt;pid&gt;.log</td>
										<td>If an error occurs, save the error data to this file. (Introduced in 6.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-ExtendedDTraceProbes</td>
										<td>Enable performance-impacting <a href="http://java.sun.com/javase/6/docs/technotes/guides/vm/dtrace.html">dtrace</a> probes. (Introduced in 6. Relevant to Solaris only.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:HeapDumpPath=./java_pid&lt;pid&gt;.hprof</td>
										<td>Path to directory or filename for heap dump. <i>Manageable</i>. (Introduced in 1.4.2 update 12, 5.0 update 7.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-HeapDumpOnOutOfMemoryError</td>
										<td>Dump heap to file when java.lang.OutOfMemoryError is thrown. <i>Manageable</i>. (Introduced in 1.4.2 update 12, 5.0 update 7.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:OnError="&lt;cmd args&gt;;&lt;cmd args&gt;"</td>
										<td>Run user-defined commands on fatal error. (Introduced in 1.4.2 update 9.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:OnOutOfMemoryError="&lt;cmd args&gt;;<br />&lt;cmd args&gt;"</td>
										<td>Run user-defined commands when an OutOfMemoryError is first thrown. (Introduced in 1.4.2 update 12, 6)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-PrintClassHistogram</td>
										<td>Print a histogram of class instances on Ctrl-Break. <i>Manageable</i>. (Introduced in 1.4.2.) The <a href="http://java.sun.com/javase/6/docs/technotes/tools/share/jmap.html">jmap -histo</a> command provides equivalent functionality.<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-PrintConcurrentLocks</td>
										<td>Print java.util.concurrent locks in Ctrl-Break thread dump. <i>Manageable</i>. (Introduced in 6.) The <a href="http://java.sun.com/javase/6/docs/technotes/tools/share/jstack.html">jstack -l</a> command provides equivalent functionality.<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-PrintCommandLineFlags</td>
										<td>Print flags that appeared on the command line. (Introduced in 5.0.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-PrintCompilation</td>
										<td>Print message when a method is compiled.<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-PrintGC</td>
										<td>Print messages at garbage collection. <i>Manageable</i>. <br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-PrintGCDetails</td>
										<td>Print more details at garbage collection. <i>Manageable</i>. (Introduced in 1.4.0.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-PrintGCTimeStamps</td>
										<td>Print timestamps at garbage collection. <i>Manageable</i> (Introduced in 1.4.0.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-PrintTenuringDistribution</td>
										<td>Print tenuring age information.<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-TraceClassLoading</td>
										<td>Trace loading of classes.<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-TraceClassLoadingPreorder</td>
										<td>Trace all classes loaded in order referenced (not loaded). (Introduced in 1.4.2.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-TraceClassResolution</td>
										<td>Trace constant pool resolutions. (Introduced in 1.4.2.)<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-TraceClassUnloading</td>
										<td>Trace unloading of classes.<br /><br /></td>
								</tr>
								<tr valign="top">
										<td>-XX:-TraceLoaderConstraints</td>
										<td>Trace recording of loader constraints. (Introduced in 6.)</td>
								</tr>
						</tbody>
				</table>
		</span>
<img src ="http://www.blogjava.net/mstar/aggbug/170579.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2007-12-26 14:23 <a href="http://www.blogjava.net/mstar/archive/2007/12/26/Java_HotSpot_VM_Options.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用JakartaCommon的net组件来做ftp下载</title><link>http://www.blogjava.net/mstar/archive/2007/11/08/use_jakarka_common_net.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Thu, 08 Nov 2007 11:21:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2007/11/08/use_jakarka_common_net.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/159147.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2007/11/08/use_jakarka_common_net.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/159147.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/159147.html</trackback:ping><description><![CDATA[这几天一个同事要在项目里实现用ftp下载文件. 遇到了很多问题. 于是我推荐他用Jakarta-Commons项目中的net组件在实现. 其实之前我也没有实际用过, 稍稍看了一下文档,知道里面有个ftp包能完成相关的操作. 于是我的同事就兴致勃勃的拿去用了. 可用了以后才发现有很多问题, 搞得焦头烂额. 经过我们的努力, 终于把问题都解决了, 下面我把遇到的问题和解决方案写下来, 以备其他想要用common-net包的朋友参考. <br /><br />首先把代码贴出来:<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> ClientTest {<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">        String url </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">172.17.1.38</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">        String user </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">test</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">        String pwd </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">test</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">        FTPClient ftp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FTPClient();<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">        ftp.setControlEncoding(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">GBK</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">        FTPClientConfig conf </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FTPClientConfig(FTPClientConfig.SYST_NT);<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">        conf.setServerLanguageCode(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">zh</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">        ftp.configure(conf);<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">            ftp.connect(url);<br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (ftp.login(user, pwd)) {<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> reply </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ftp.getReplyCode();<br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">FTPReply.isPositiveCompletion(reply)) {<br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">                    ftp.disconnect();<br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">                    System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">disconnect</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">                } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">                    ftp.enterLocalPassiveMode();<br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">                    ftp.setFileType(FTP.BINARY_FILE_TYPE);<br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">                    File dir </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">down</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">                    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">dir.exists()) {<br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">                        dir.mkdirs();<br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">                    }<br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);">                    String[] names </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ftp.listNames();<br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 0, 0);">                    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (String name : names) {<br /></span><span style="color: rgb(0, 128, 128);">31</span> <span style="color: rgb(0, 0, 0);">                        File file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File(dir.getPath() </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> File.separator </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> name);<br /></span><span style="color: rgb(0, 128, 128);">32</span> <span style="color: rgb(0, 0, 0);">                        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">file.exists()) {<br /></span><span style="color: rgb(0, 128, 128);">33</span> <span style="color: rgb(0, 0, 0);">                            file.createNewFile();<br /></span><span style="color: rgb(0, 128, 128);">34</span> <span style="color: rgb(0, 0, 0);">                        }<br /></span><span style="color: rgb(0, 128, 128);">35</span> <span style="color: rgb(0, 0, 0);">                        </span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> pos </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> file.length();<br /></span><span style="color: rgb(0, 128, 128);">36</span> <span style="color: rgb(0, 0, 0);">                        RandomAccessFile raf </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> RandomAccessFile(file, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">rw</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">37</span> <span style="color: rgb(0, 0, 0);">                        raf.seek(pos);<br /></span><span style="color: rgb(0, 128, 128);">38</span> <span style="color: rgb(0, 0, 0);">                        ftp.setRestartOffset(pos);<br /></span><span style="color: rgb(0, 128, 128);">39</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">40</span> <span style="color: rgb(0, 0, 0);">                        InputStream is </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ftp.retrieveFileStream(name);<br /></span><span style="color: rgb(0, 128, 128);">41</span> <span style="color: rgb(0, 0, 0);">                        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (is </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {<br /></span><span style="color: rgb(0, 128, 128);">42</span> <span style="color: rgb(0, 0, 0);">                            System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">no such file:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> name);<br /></span><span style="color: rgb(0, 128, 128);">43</span> <span style="color: rgb(0, 0, 0);">                        } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">44</span> <span style="color: rgb(0, 0, 0);">                            System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">start getting file:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> name);<br /></span><span style="color: rgb(0, 128, 128);">45</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">46</span> <span style="color: rgb(0, 0, 0);">                            </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> b;<br /></span><span style="color: rgb(0, 128, 128);">47</span> <span style="color: rgb(0, 0, 0);">                            </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> ((b </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> is.read()) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">) {<br /></span><span style="color: rgb(0, 128, 128);">48</span> <span style="color: rgb(0, 0, 0);">                                raf.write(b);<br /></span><span style="color: rgb(0, 128, 128);">49</span> <span style="color: rgb(0, 0, 0);">                            }<br /></span><span style="color: rgb(0, 128, 128);">50</span> <span style="color: rgb(0, 0, 0);">                            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (ftp.getReply() </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> FTPReply.CODE_226) {<br /></span><span style="color: rgb(0, 128, 128);">51</span> <span style="color: rgb(0, 0, 0);">                                System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">done!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">52</span> <span style="color: rgb(0, 0, 0);">                            }<br /></span><span style="color: rgb(0, 128, 128);">53</span> <span style="color: rgb(0, 0, 0);">                            is.close();<br /></span><span style="color: rgb(0, 128, 128);">54</span> <span style="color: rgb(0, 0, 0);">                        }<br /></span><span style="color: rgb(0, 128, 128);">55</span> <span style="color: rgb(0, 0, 0);">                        raf.close();<br /></span><span style="color: rgb(0, 128, 128);">56</span> <span style="color: rgb(0, 0, 0);">                    }<br /></span><span style="color: rgb(0, 128, 128);">57</span> <span style="color: rgb(0, 0, 0);">                }<br /></span><span style="color: rgb(0, 128, 128);">58</span> <span style="color: rgb(0, 0, 0);">                ftp.logout();<br /></span><span style="color: rgb(0, 128, 128);">59</span> <span style="color: rgb(0, 0, 0);">            }<br /></span><span style="color: rgb(0, 128, 128);">60</span> <span style="color: rgb(0, 0, 0);">        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (IOException e) {<br /></span><span style="color: rgb(0, 128, 128);">61</span> <span style="color: rgb(0, 0, 0);">            e.printStackTrace();<br /></span><span style="color: rgb(0, 128, 128);">62</span> <span style="color: rgb(0, 0, 0);">        }<br /></span><span style="color: rgb(0, 128, 128);">63</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">64</span> <span style="color: rgb(0, 0, 0);">}</span></div><p><br />一, 文件名中文乱码问题.<br />开始知道能用FTPClient的listNames方法得到当前目录下所有文件的列表. 但是发现中文文件名是乱码. 默认情况下FTPClient使用UTF-8字符集作为和服务器通讯的编码集. 而我们的ftp服务器是在中文windowsXP上装的ServU. 所有使用GBK做为通讯编码集. 经过查找api文档, 我看到了setControlEncoding方法, 试了一下,果然好使. 于是这个问题就解决了:<br />第8行: ftp.setControlEncoding("GBK")<br />至于conf.setServerLanguageCode("zh")对这个有什么影响,我还没有验证. 但是只有这句是不行的.<br /><br />二, 传输binary文件, 由于FTPClient默认使用ASCII作为传输模式, 所有不能传输二进制文件. 通过<br />ftp.setFileType(FTP.BINARY_FILE_TYPE)个可以解决这个问题, 但是要在login以后执行. 因为这个方法要向服务器发送"TYPE I"命令.<br />开始的时候用的是<a href="file:///F:/Resource/Java_Resource/Jakarta-Common/commons-net-1.4.1/docs/apidocs/org/apache/commons/net/ftp/FTPClient.html#setFileTransferMode%28int%29"><font face="Courier New">setFileTransferMode</font></a>, 不过不好使. 它会执行 MODE I命令, 服务器不接受.<br /><br />三, 用被动模式传输: enterLocalPassiveMode()这个到不用在login之后执行, 因为它只改变FTPClient实例的内部属性.<br /><br />四, 断点续传. 心想应该有支持吧, 于是查API结果找到了setRestartOffset()方法, 试了一下,果真好使. 用RandomAccessFile配合使用, 实现起来还是蛮简单的.</p><p>五, 只能传一个文件!!<br />不知道大家有没有遇到这个问题, 传输第一个文件好使, 后面的的retrieveFileStream(name)都是返回null. 这个实在是令人头痛的问题, 难不成要传一个文件重新建立一次连接? 那样也太土了吧. 但是文档里也没有写, 来点狠的,debug它的源码, 看看它究竟做了什么事情. 首先看一下ftp服务器的日志, 发现日志没问题, 过来的命令和reply都是正确的, 但是发现第一个文件以后没有执行RETR命令. 于是跟踪PASV命令的reply代码,发现不是227,而服务器上的日志明明返回的是227. 难道是FTPClient解析Reply出问题了. 进一步跟踪发现了问题, 原来在一个文件传输过程中会产生两个Reply:<br />150 Opening BINARY mode data connection for a.sql (19890 Bytes).<br />226 Transfer complete.<br />而FTPClient自动消费掉一个,于是解析Reply就发生了错位, 下一个命令的会解析266那条. 接下来的命令都不是解析自己的Reply而是前一次命令的. 所有在PASV命令的Reply码就不对了, FTPClient也就不会执行接下来本应该执行RETR命令.<br />他不消费,我们来消费吧. 于是在文件传输完成以后, 主动调用一次getReply()把接下来的226消费掉. 这样做是可以解决这个暂时的问题, 但不知道在其他的ftp操作上会不会也有类似的情况. FTPClient这点可做的不大好. </p><p><strike>对于上面这个问题, 我本来想修改一下FTPClient这个类来彻底解决问题. 结果发现自己也想不出好办法. 最后还是放弃了.</strike></p>
今天才发现,原来FTPClient有个<strong>completePendingCommand</strong>()方法就是用来干这件事情的!<br /><br />完成的程序,上传,下载,删除<br />http://www.blogjava.net/Files/mstar/ClientTest.zip<br /><img src ="http://www.blogjava.net/mstar/aggbug/159147.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2007-11-08 19:21 <a href="http://www.blogjava.net/mstar/archive/2007/11/08/use_jakarka_common_net.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>真怀疑自己还是不是程序员</title><link>http://www.blogjava.net/mstar/archive/2006/11/28/84111.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Tue, 28 Nov 2006 10:21:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2006/11/28/84111.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/84111.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2006/11/28/84111.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/84111.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/84111.html</trackback:ping><description><![CDATA[昨天同事问我一个小问题：给一组数，按照任意相邻的两个数的绝对值不大于5排序，列出所有情况。想了好长时间，利用工作空闲时间编了一段python程序，感觉算法不怎么好。就是递归遍历所有的情况，把不符合的剔除。已经工作快两年了，反而发现自己编程序还不如以前了。什么，数据结构，算法，SQL都忘得差不多了，就会编点简单的Java程序。这样下去，要废掉了……。<br /><br />程序在这里：<br /><a href="/Files/mstar/fuck_sort.zip">http://www.blogjava.net/Files/mstar/fuck_sort.zip</a><img src ="http://www.blogjava.net/mstar/aggbug/84111.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2006-11-28 18:21 <a href="http://www.blogjava.net/mstar/archive/2006/11/28/84111.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>今天遇到了一个Calendar的问题，大家看看！</title><link>http://www.blogjava.net/mstar/archive/2006/08/31/66825.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Thu, 31 Aug 2006 03:59:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2006/08/31/66825.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/66825.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2006/08/31/66825.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/66825.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/66825.html</trackback:ping><description><![CDATA[今天发现了前一段时间做的系统的一个关于日期的Bug。开始还以为是Calendar的Bug，想了一会突然发现是自己的问题。<br /><br />假设今天系统时间是2006年8月31号。<br /><br />下面是一段代码<br /><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"><span style="COLOR: #000000">{<br />        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> year </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2006</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> month </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;<br />        Calendar cal </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Calendar.getInstance();<br />        cal.set(Calendar.YEAR, year);<br />        cal.set(Calendar.MONTH, month </span><span style="COLOR: #000000">- </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br />        System.out.println(cal.get(Calendar.MONTH)); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">这里应该是多少？</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        SimpleDateFormat df </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SimpleDateFormat(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">yyyyMM</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        System.out.println(df.format(cal.getTime()));<br />}</span></div><br />原来预想的结果是： 8 和200609<br />结果是 9 和 200610<br /><br />所以在这个系统里，如果8月31号查询9月的内容，会把10月的查出来。<br /><br />其实是Calendar.getIntance()方法返回的Calendar里面的默认时间是当前系统时间。<br />所以这时的Calendar里Day是31.如果把Month设置成8（九月）。Calendar中的时间就是9月31号，而9月没有31号，所以就变成了10月1号。这时你在取month的值就变成了9（十月）。<br /><br />想明白以后，我捶胸顿足啊！ 以后用Calendar的时候要小心了。<img src ="http://www.blogjava.net/mstar/aggbug/66825.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2006-08-31 11:59 <a href="http://www.blogjava.net/mstar/archive/2006/08/31/66825.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[翻译]Tomcat5.5 Class Loader HOW-TO</title><link>http://www.blogjava.net/mstar/archive/2006/08/24/65511.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Thu, 24 Aug 2006 06:39:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2006/08/24/65511.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/65511.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2006/08/24/65511.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/65511.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/65511.html</trackback:ping><description><![CDATA[
		<p>
				<a href="http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html">
						<font color="#000000" size="3">http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html</font>
				</a>
		</p>
		<h2>Tomcat Class Loader HOW-TO</h2>
		<p>当Tomcat5启动以后，它创建一系列类加载器。这些类加载器以父子关系组织在一起，父类加载器在子类加载器的上面：</p>
		<div align="left">      Bootstrap<br />          |<br />       System<br />          |<br />       Common<br />      /      \<br />Catalina   Shared<br />                     /   \<br />        Webapp1  Webapp2 ... </div>
		<p>这些类加载器所扮演的角色，以及它们可以见到的类和资源的规则如下：<br /><br />如上图所示，Tomcat5 在初始化的时候创建如下类加载器：<br /><strong><br />Bootstrap</strong> - 这个类加载器可以加载Java虚拟机的运行时基础类，以及在系统扩展目录(<code>$JAVA_HOME/jre/lib/ext</code>)中的所有Jar包中的类。<strong>注意</strong>－一些JVM可能用多个类加载器来实现它，或者它是根本不能被看见的。<br /><strong><br />System</strong> - 这个类加载器一般可以加载<font face="Courier New">CLASSPATH环境变量的内容。所有这个类对于Tomcat内部的类和web应用程序的都是可见的。尽管如此，标准的Tomcat5启动脚本(<code>$CATALINA_HOME/bin/catalina.sh</code> 或 <code>%CATALINA_HOME%\bin\catalina.bat</code>)都会忽略CLASSPATH环境变量，取而代之的是从如下仓库加载：</font></p>
		<ul>
				<li>$CATALINA_HOME/bin/bootstrap.jar - 包含Tomcat5 服务器初始化的main()方法，以及所需的类加载器的实现类。 
</li>
				<li>$JAVA_HOME/lib/tools.jar - 包括把JSP页面编译成Serlet类所需的"javac"编译器. 
</li>
				<li>$CATALINA_HOME/bin/commons-logging-api.jar - Jakarta commons logging API. 
</li>
				<li>$CATALINA_HOME/bin/commons-daemon.jar - Jakarta commons daemon API. 
</li>
				<li>jmx.jar - The JMX 1.2 实现. </li>
		</ul>
		<p dir="ltr" style="MARGIN-RIGHT: 0px">
				<strong>Common</strong> - 这个类加载器可以使一些附加的类对于<font face="Courier New">Tomcat内部的类和web应用程序可见。正常情况下，应用程序不应该替换它。所有$CATALINA_HOME/common/classes目录下的未打包类和资源，以及$CATALINA_HOME/commons/endorsed、$CATALINA_HOME/commons/i18n、$CATALINA_HOME/common/lib目录下的Jar包中的类和资源都是这个类加载器的加载对象。默认情况，包括如下内容：</font><em>         </em><em></em></p>
		<ul>
				<li>commons-el.jar - Jakarta commons el, Jasper用的EL表达式实现 
</li>
				<li>jasper-compiler.jar - The JSP 2.0 编译器. 
</li>
				<li>jasper-compiler-jdt.jar - The Eclipse JDT Java 编译器. 
</li>
				<li>jasper-runtime.jar - The JSP 2.0 运行库. 
</li>
				<li>jsp-api.jar - The JSP 2.0 API. 
</li>
				<li>naming-common.jar - Tomcat5的JNDI 实现，用于内存命名环境 
</li>
				<li>naming-factory.jar - Tomcat5的JNDI 实现，用于企业级资源引用(EJB, connection pools). 
</li>
				<li>naming-factory-dbcp.jar - Jakarta commons DBCP, 为Web应用程序提供JDBC连接池。这个类已经从默认的org.apache.commons包中移出。 
</li>
				<li>naming-java.jar -  java命名空间处理器. 
</li>
				<li>naming-resources.jar - The specialized JNDI naming context implementation used to represent the static resources of a web application. This is not related to the support of the J2EE ENC, and cannot be removed. 
</li>
				<li>servlet-api.jar - The Servlet 2.4 API. 
</li>
				<li>tomcat-i18n-**.jar - Optional JARs containing resource bundles for other languages. As default bundles are also included in each individual JAR, they can be safely removed if no internationalization of messages is needed. </li>
		</ul>
		<p>
				<strong>Catalina</strong> - 这个类加载器主要加载Tomcat5自己所需要的类和资源。这些类和资源对于Web应用程序是完全不可见的。在<font face="Courier New">$CATALINA_HOME/server/classes目录下的所有类和资源，$CATALINA_HOME/server/lib下的所有Jar包中类和资源是这个类加载器的加载对象。默认情况，包括个如下内容：</font></p>
		<ul>
				<li>catalina.jar - Tomcat5中Catalina Servlet容器的实现部分。 
</li>
				<li>catalina-ant.jar - 在管理web应用程序时要用倒的一些Ant任务。 
</li>
				<li>catalina-optional.jar - 一些Catalina可选组件。 
</li>
				<li>commons-modeler.jar - Tomcat通过JMX暴露其内部对象是用的一些MBean实现。 
</li>
				<li>servlets-xxxxx.jar - 这些类同内部的Servlet一起提供Tomcat的部分功能，它们都是独立的，所以如果不需要相应的服务可以将其删除。或者它们可以从属于特定的安全管理器。 
</li>
				<li>tomcat-coyote.jar - Coyote API.。 
</li>
				<li>tomcat-http.jar - 标准的Java HTTP/1.1 连接器.。 
</li>
				<li>tomcat-ajp.jar - <code>AJP</code> web 服务器的连接器，一般用于Apache，iPlanet iAS和 iWS.。 
</li>
				<li>tomcat-util.jar - Tomcat连接器需要的工具类。 </li>
		</ul>
		<p>
				<strong>Shared</strong> - 这个类加载器用于把一些类和资源共享给<strong>所有</strong>的web应用程序。(除非Tomcat内部的类也需要访问这些类，在这种情况下你应该把它们放在<strong>Common</strong>类加载能加载的地方). 在<font face="Courier New">$CATALINA_BASE/shared/classes目录下的所有未打包类和资源，以及$CATALINA_BASE/shared/lib目录下的所有Jar包中的类和资源可以被其加载。如果通过$CATALINA_BASE环境变量来从同一个tomcat程序运行了多个在实例，那么这个类加载器的仓库是相对于$CATALINA_BASE而不是$CATALINA_HOME。</font> </p>
		<p>
				<strong>WebappX</strong> - 系统会为部署在一个Tomcat实例中的每个应用程序创建一个这样的类加载器，它们为所属的应用程序加载类。所有你的web应用程序包的<font face="Courier New">/WEB-INF/classes目录下的类和资源，以及</font><br /><font face="Courier New">/WEB-INF/lib</font> 目录下的所有Jar包中的类和资源是这个类的加载对象。这些类和资源仅对这个应用程序可见，并且这个应用程序也看不见其他应用程序的类和资源。<br /><br />就像上面所描述的，web应用程序的类加载的加载流程与默认的Java 2的类记载托管模型是<strong>不一样</strong>的。当有一个请求需要应用程序的<em>WebappX</em> 类加载器加载一个类的时候，这个类加载器是<strong>首先</strong>到自己的仓库中查找，而不是先交给上面的类加载器查找。这里有一些例外。JRE的基础类是不能被覆盖的。对于其他一些类（如J2SE 1.4+中的XML解析器组件），可以使用J2SE1.4的签名特性。最后任何包括servlet API类的Jar包会被忽略。Tomcat5中的其他的类加载器使用正常托管模式。</p>
		<p dir="ltr" style="MARGIN-RIGHT: 0px">这样在一个web应用程序中，类和资源的加载顺序是这样：</p>
		<p dir="ltr" style="MARGIN-RIGHT: 0px">
		</p>
		<ul>
				<li>Bootstrap classes of your JVM 
</li>
				<li>System class loader classses (described above) 
</li>
				<li>
						<em>/WEB-INF/classes</em> of your web application 
</li>
				<li>
						<em>/WEB-INF/lib/*.jar</em> of your web application 
</li>
				<li>
						<em>$CATALINA_HOME/common/classes</em>
				</li>
				<li>
						<em>$CATALINA_HOME/common/endorsed/*.jar</em>
				</li>
				<li>
						<em>$CATALINA_HOME/common/i18n/*.jar</em>
				</li>
				<li>
						<em>$CATALINA_HOME/common/lib/*.jar</em>
				</li>
				<li>
						<em>$CATALINA_BASE/shared/classes</em>
				</li>
				<li>
						<em>$CATALINA_BASE/shared/lib/*.jar</em>
				</li>
		</ul>
<img src ="http://www.blogjava.net/mstar/aggbug/65511.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2006-08-24 14:39 <a href="http://www.blogjava.net/mstar/archive/2006/08/24/65511.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ClassLoader中的方法</title><link>http://www.blogjava.net/mstar/archive/2006/08/24/65508.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Thu, 24 Aug 2006 06:16:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2006/08/24/65508.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/65508.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2006/08/24/65508.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/65508.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/65508.html</trackback:ping><description><![CDATA[
		<a href="http://www.xici.net/b228402/d11821837.htm">http://www.xici.net/b228402/d11821837.htm</a>
		<br />
		<br />方法 loadClass<br /><br />ClassLoader.loadClass() 是 ClassLoader 的入口点。其特征如下：<br />Class loadClass( String name, boolean resolve );<br />name 参数指定了 JVM 需要的类的名称，该名称以包表示法表示，如 Foo 或 java.lang.Object。 resolve 参数告诉方法是否需要解析类。在准备执行类之前，应考虑类解析。并不总是需要解析。如果 JVM 只需要知道该类是否存在或找出该类的超类，那么就不需要解析。<br />在 Java 版本 1.1 和以前的版本中，loadClass 方法是创建定制的 ClassLoader 时唯一需要覆盖的方法。（Java 2 中 ClassLoader 的变动提供了关于 Java 1.2 中 findClass() 方法的信息。）<br /><br /><br />方法 defineClass<br /><br /><br />defineClass 方法是 ClassLoader 的主要诀窍。该方法接受由原始字节组成的数组并把它转换成 Class 对象。原始数组包含如从文件系统或网络装入的数据。<br /><br />defineClass 管理 JVM 的许多复杂、神秘和倚赖于实现的方面 -- 它把字节码分析成运行时数据结构、校验有效性等等。不必担心，您无需亲自编写它。事实上，即使您想要这么做也不能覆盖它，因为它已被标记成最终的。<br /><br /><br />方法 findSystemClass<br /><br /><br />findSystemClass 方法从本地文件系统装入文件。它在本地文件系统中寻找类文件，如果存在，就使用 defineClass 将原始字节转换成 Class 对象，以将该文件转换成类。当运行 Java 应用程序时，这是 JVM 正常装入类的缺省机制。（Java 2 中 ClassLoader 的变动提供了关于 Java 版本 1.2 这个过程变动的详细信息。）<br /><br />对于定制的 ClassLoader，只有在尝试其它方法装入类之后，再使用 findSystemClass。原因很简单：ClassLoader 是负责执行装入类的特殊步骤，不是负责所有类。例如，即使 ClassLoader 从远程的 Web 站点装入了某些类，仍然需要在本地机器上装入大量的基本 Java 库。而这些类不是我们所关心的，所以要 JVM 以缺省方式装入它们：从本地文件系统。这就是 findSystemClass 的用途。<br /><br />其工作流程如下：<br />请求定制的 ClassLoader 装入类。<br />检查远程 Web 站点，查看是否有所需要的类。<br />如果有，那么好；抓取这个类，完成任务。<br />如果没有，假定这个类是在基本 Java 库中，那么调用 findSystemClass，使它从文件系统装入该类。<br /><br /><br />在大多数定制 ClassLoaders 中，首先调用 findSystemClass 以节省在本地就可以装入的许多 Java 库类而要在远程 Web 站点上查找所花的时间。然而，正如，在下一章节所看到的，直到确信能自动编译我们的应用程序代码时，才让 JVM 从本地文件系统装入类。<br /><br /><br />方法 resolveClass<br />正如前面所提到的，可以不完全地（不带解析）装入类，也可以完全地（带解析）装入类。当编写我们自己的 loadClass 时，可以调用 resolveClass，这取决于 loadClass 的 resolve 参数的值。<br /><br /><br />方法 findLoadedClass<br />findLoadedClass 充当一个缓存：当请求 loadClass 装入类时，它调用该方法来查看 ClassLoader 是否已装入这个类，这样可以避免重新装入已存在类所造成的麻烦。应首先调用该方法。<br /><img src ="http://www.blogjava.net/mstar/aggbug/65508.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2006-08-24 14:16 <a href="http://www.blogjava.net/mstar/archive/2006/08/24/65508.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ClassLoader原理</title><link>http://www.blogjava.net/mstar/archive/2006/08/24/65505.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Thu, 24 Aug 2006 06:01:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2006/08/24/65505.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/65505.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2006/08/24/65505.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/65505.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/65505.html</trackback:ping><description><![CDATA[
		<h2 class="diaryTitle">ClassLoader原理</h2>
		<p>
				<a href="http://jamesdu.blogchina.com/349567.html">http://jamesdu.blogchina.com/349567.html</a>                                       </p>
		<p>
				<strong> </strong>JVM规范定义了两种类型的类装载器：<strong>启动内装载器</strong><strong>(bootstrap)</strong><strong>和用户自定义装载器</strong><strong>(user-defined class loader)</strong>。 <br /><br /><strong><br /></strong><br /><strong> <br /></strong><strong>一．    </strong><strong>ClassLoader</strong><strong>基本概念</strong><strong><br /></strong><strong>1</strong><strong>．</strong><strong>ClassLoader</strong><strong>分类</strong><strong><br /></strong>类装载器是用来把类(class)装载进JVM的。<br />JVM规范定义了两种类型的类装载器：<strong>启动内装载器</strong><strong>(bootstrap)</strong><strong>和用户自定义装载器</strong><strong>(user-defined class loader)</strong>。 <br /><br /><strong><br /></strong><strong>JVM在运行时会产生三个ClassLoader:Bootstrap ClassLoader、Extension ClassLoader和AppClassLoader.</strong>Bootstrap是用C++编写的，我们在Java中看不到它,是null,是JVM自带的类装载器，用来装载核心类库，如java.lang.*等。<br /><strong>AppClassLoader</strong><strong>的</strong><strong>Parent</strong><strong>是</strong><strong>ExtClassLoader</strong><strong>，而</strong><strong>ExtClassLoader</strong><strong>的</strong><strong>Parent</strong><strong>为</strong><strong>Bootstrap ClassLoader</strong><strong>。</strong><br /> <br /><strong>Java</strong><strong>提供了抽象类</strong><strong>ClassLoader</strong><strong>，所有用户自定义类装载器都实例化自</strong><strong>ClassLoader</strong><strong>的子类。</strong><strong> System Class Loader</strong><strong>是一个特殊的用户自定义类装载器，由</strong><strong>JVM</strong><strong>的实现者提供，在编程者不特别指定装载器的情况下默认装载用户类</strong>。系统类装载器可以通过ClassLoader.getSystemClassLoader() 方法得到。<br /> <br />例1，测试你所使用的JVM的ClassLoader<br />/*LoaderSample1.java*/<br /></p>
		<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">
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> LoaderSample1 {<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">static</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> main(String[] args) {<br />        Class c;<br />        ClassLoader cl;<br />        cl </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> ClassLoader.getSystemClassLoader();<br />        System.out.println(cl);<br />        </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000"> (cl </span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">) {<br />            cl </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> cl.getParent();<br />            System.out.println(cl);<br />        }<br />        </span>
				<span style="COLOR: #0000ff">try</span>
				<span style="COLOR: #000000"> {<br />            c </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> Class.forName(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">java.lang.Object</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />            cl </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> c.getClassLoader();<br />            System.out.println(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">java.lang.Object's loader is </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> cl);<br />            c </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> Class.forName(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">LoaderSample1</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />            cl </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> c.getClassLoader();<br />            System.out.println(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">LoaderSample1's loader is </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> cl);<br />        } </span>
				<span style="COLOR: #0000ff">catch</span>
				<span style="COLOR: #000000"> (Exception e) {<br />            e.printStackTrace();<br />        }<br />    }<br />}</span>
		</div>
		<p>
				<br />在我的机器上(Sun Java 1.4.2)的运行结果<br /><font color="#0066ff">sun.misc.Launcher$AppClassLoader@1a0c10f<br />sun.misc.Launcher$ExtClassLoader@e2eec8<br />null <br />java.lang.Object's loader is null<br />LoaderSample1's loader is sun.misc.Launcher$AppClassLoader@1a0c10f</font><br />第一行表示，系统类装载器实例化自类sun.misc.Launcher$AppClassLoader <br />第二行表示，系统类装载器的parent实例化自类sun.misc.Launcher$ExtClassLoader <br />第三行表示，系统类装载器parent的parent为bootstrap <br />第四行表示，核心类java.lang.Object是由bootstrap装载的 <br />第五行表示，用户类LoaderSample1是由系统类装载器装载的 <br /> <br /> <br /><strong>二．</strong><strong>parent delegation模型</strong><strong><br /></strong>从1.2版本开始，Java引入了双亲委托模型，从而更好的保证Java平台的安全。<strong>在此模型下，当一个装载器被请求装载某个类时，它首先委托自己的</strong><strong>parent</strong><strong>去装载，若</strong><strong>parent</strong><strong>能装载，则返回这个类所对应的</strong><strong>Class</strong><strong>对象，若</strong><strong>parent</strong><strong>不能装载，则由</strong><strong>parent</strong><strong>的请求者去装载</strong>。<br /><br />图 1 parent delegation模型<br />如图1所示，loader2的parent为loader1，loader1的parent为system class loader。假设loader2被要求装载类MyClass，在parent delegation模型下，loader2首先请求loader1代为装载，loader1再请求系统类装载器去装载MyClass。若系统装载器能成功装载，则将MyClass所对应的Class对象的reference返回给loader1，loader1再将reference返回给loader2，从而成功将类MyClass装载进虚拟机。若系统类装载器不能装载MyClass，loader1会尝试装载MyClass，若loader1也不能成功装载，loader2会尝试装载。若所有的parent及loader2本身都不能装载，则装载失败。<br /> <br />若有一个能成功装载，实际装载的类装载器被称为定义类装载器，所有能成功返回Class对象的装载器（包括定义类装载器）被称为初始类装载器。如图1所示，假设loader1实际装载了MyClass，则loader1为MyClass的定义类装载器，loader2和loader1为MyClass的初始类装载器。<br /> <br />需要指出的是，Class Loader是对象，它的父子关系和类的父子关系没有任何关系。<br /> <br />那么parent delegation模型为什么更安全了？<strong>因为在此模型下用户自定义的类装载器不可能装载应该由父亲装载器装载的可靠类，从而防止不可靠甚至恶意的代码代替由父亲装载器装载的可靠代码。实际上，类装载器的编写者可以自由选择不用把请求委托给</strong><strong>parent</strong><strong>，但正如上所说，会带来安全的问题。</strong><strong><br /></strong><strong> <br /></strong> <br /><strong>三．命名空间及其作用</strong><strong><br /></strong>每个类装载器有自己的命名空间，命名空间由所有以此装载器为创始类装载器的类组成。不同命名空间的两个类是不可见的，但只要得到类所对应的Class对象的reference，还是可以访问另一命名空间的类。<br /> <br />例2演示了一个命名空间的类如何使用另一命名空间的类。在例子中，LoaderSample2由系统类装载器装载，LoaderSample3由自定义的装载器loader负责装载，两个类不在同一命名空间，但LoaderSample2得到了LoaderSample3所对应的Class对象的reference，所以它可以访问LoaderSampl3中公共的成员(如age)。<br />例2不同命名空间的类的访问<br />/*LoaderSample2.java*/<br /></p>
		<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">
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.net.</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.lang.reflect.</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> LoaderSample2 {<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">static</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> main(String[] args) {<br />        </span>
				<span style="COLOR: #0000ff">try</span>
				<span style="COLOR: #000000"> {<br />            String path </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> System.getProperty(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">user.dir</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />            URL[] us </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> {</span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> URL(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">file://</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> path </span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">/sub/</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)};<br />            ClassLoader loader </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> URLClassLoader(us);<br />            Class c </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> loader.loadClass(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">LoaderSample3</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />            Object o </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> c.newInstance();<br />            Field f </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> c.getField(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">age</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />            </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> age </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> f.getInt(o);<br />            System.out.println(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">age is </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> age);<br />        } </span>
				<span style="COLOR: #0000ff">catch</span>
				<span style="COLOR: #000000"> (Exception e) {<br />            e.printStackTrace();<br />        }<br />    }<br />}</span>
		</div>
		<p>
				<br />/*sub/Loadersample3.java*/</p>
		<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">
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> LoaderSample3 {<br />    </span>
				<span style="COLOR: #0000ff">static</span>
				<span style="COLOR: #000000"> {<br />        System.out.println(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">LoaderSample3 loaded</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />    }<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> age </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">30</span>
				<span style="COLOR: #000000">;<br />}</span>
		</div>
		<p>编译：javac LoaderSample2.java; javac sub/LoaderSample3.java<br />运行：java LoaderSample2<br />LoaderSample3 loaded<br />age is 30<br />从运行结果中可以看出，在类LoaderSample2中可以创建处于另一命名空间的类LoaderSample3中的对象并可以访问其公共成员age。<br />运行时包(runtime package)<br />由同一类装载器定义装载的属于相同包的类组成了运行时包，决定两个类是不是属于同一个运行时包，不仅要看它们的包名是否相同，还要看的定义类装载器是否相同。只有属于同一运行时包的类才能互相访问包可见的类和成员。这样的限制避免了用户自己的代码冒充核心类库的类访问核心类库包可见成员的情况。假设用户自己定义了一个类java.lang.Yes，并用用户自定义的类装载器装载，由于java.lang.Yes和核心类库java.lang.*由不同的装载器装载，它们属于不同的运行时包，所以java.lang.Yes不能访问核心类库java.lang中类的包可见的成员。 <br /> <br /><strong>总结</strong><strong><br /></strong><strong>命名空间并没有完全禁止属于不同空间的类的互相访问，双亲委托模型加强了</strong><strong>Java</strong><strong>的安全，运行时包增加了对包可见成员的保护。</strong><strong><br /></strong><strong> <br /></strong><strong>二．    </strong><strong>扩展ClassLoader</strong><strong>方法</strong><strong><br /></strong>我们目的是从本地文件系统使用我们实现的类装载器装载一个类。<strong>为了创建自己的类装载器我们应该扩展</strong><strong>ClassLoader</strong><strong>类，这是一个抽象类。我们创建一个</strong><strong>FileClassLoader extends ClassLoader</strong><strong>。我们需要覆盖</strong><strong>ClassLoader</strong><strong>中的</strong><strong>findClass(String name)</strong><strong>方法，这个方法通过类的名字而得到一个</strong><strong>Class</strong><strong>对象。</strong><br /></p>
		<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">
				<span style="COLOR: #000000">    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> Class findClass(String name)<br />    {<br />        </span>
				<span style="COLOR: #0000ff">byte</span>
				<span style="COLOR: #000000">[] data </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> loadClassData(name);<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> defineClass(name, data, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, data.length);<br />    }</span>
		</div>
		<p>
				<br />
				<strong>   我们还应该提供一个方法loadClassData(String name)，通过类的名称返回class文件的字</strong>
				<strong>
						<br />
				</strong>
				<strong>节数组。然后使用ClassLoader提供的defineClass()方法我们就可以返回Class对象了。</strong>
				<br />
		</p>
		<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">
				<span style="COLOR: #000000">    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">byte</span>
				<span style="COLOR: #000000">[] loadClassData(String name)<br />    {<br />        FileInputStream fis </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">byte</span>
				<span style="COLOR: #000000">[] data </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">try</span>
				<span style="COLOR: #000000">
						<br />        {<br />            fis </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> FileInputStream(</span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> File(drive </span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> name </span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> fileType));<br />            ByteArrayOutputStream baos </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> ByteArrayOutputStream();<br />            </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> ch </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />            </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000"> ((ch </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> fis.read()) </span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">)<br />            {<br />                baos.write(ch);<br />               <br />            }<br />            data </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> baos.toByteArray();<br />        } </span>
				<span style="COLOR: #0000ff">catch</span>
				<span style="COLOR: #000000"> (IOException e)<br />        {<br />            e.printStackTrace();<br />        }<br />        <br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> data;<br />    }</span>
		</div>
<img src ="http://www.blogjava.net/mstar/aggbug/65505.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2006-08-24 14:01 <a href="http://www.blogjava.net/mstar/archive/2006/08/24/65505.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>utf-8 编码问题</title><link>http://www.blogjava.net/mstar/archive/2006/08/23/65265.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Wed, 23 Aug 2006 06:09:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2006/08/23/65265.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/65265.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2006/08/23/65265.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/65265.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/65265.html</trackback:ping><description><![CDATA[
		<p>
				<font size="4">
						<a href="http://blog.csdn.net/zhangxiaoxiang/archive/2006/08/22/1106714.aspx">http://blog.csdn.net/zhangxiaoxiang/archive/2006/08/22/1106714.aspx</a>
						<br />
						<br />问题：<br /></font>public class TestUTF8<br />{<br />   public static void main(String [] args) throws Exception<br />   {<br />       byte[] bytes = {(byte)0xC0,(byte)0xB1};<br />       String str = new String(bytes,"UTF-8");<br />       System.out.println(str.getBytes("UTF-8").length); <br />   }<br />}<br /><br />程序运行后打印的结果如下：<br />1<br /><br />这个程序将 <strong>两个 </strong>字节的bytes数组按UTF-8编码转换成字符串，再将结果字符串转换成UTF-8编码的字节数组，打印出的这个字节数组的长度为 <strong>1 </strong>。为什么两个字节的数组转换成的字符串反转回去的字节数组的长度却为一呢？ <br /><br /><font size="4">答案：</font><br />这个问题应该是由UTF-8编码的特点造成的。 <br />UTF-8是一种变长字节编码方式。对于某一个字符的UTF-8编码，如果只有一个字节则其最高二进制位为0；如果是多字节，其第一个字节从最高位开始，连续的二进制位值为1的个数决定了其编码的位数，其余各字节均以10开头。UTF-8最多可用到6个字节。 <br />如表： <br />1字节 0xxxxxxx <br />2字节 110xxxxx 10xxxxxx <br />3字节 1110xxxx 10xxxxxx 10xxxxxx <br />4字节 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx <br />5字节 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx <br />6字节 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx <br />因此UTF-8中可以用来表示字符编码的实际位数最多有31位，即上表中x所表示的位。除去那些控制位（每字节开头的10等），这些x表示的位与UNICODE编码是一一对应的，位高低顺序也相同。 <br />实际将UNICODE转换为UTF-8编码时应先去除高位0，然后根据所剩编码的位数决定所需最小的UTF-8编码位数。 <br />因此那些基本ASCII字符集中的字符（UNICODE兼容ASCII）只需要一个字节的UTF-8编码（7个二进制位）便可以表示。 <br /><br />对于上面的问题，代码中给出的两个字节是 <br />十六进制：C0 B1 <br />二进制：11000000 10110001 <br />对比两个字节编码的表示方式： <br />110xxxxx 10xxxxxx <br />提取出对应的UNICODE编码： <br />00000 110001 <br />可以看出此编码并非“标准”的UTF-8编码，因为其第一个字节的“有效编码”全为0，去除高位0后的编码仅有6位。由前面所述，此字符仅用一个字节的UTF-8编码表示就够了。 <br />JAVA在把字符还原为UTF-8编码时，是按照“标准”的方式处理的，因此我们得到的是仅有1个字节的编码。 <br /><br />大家可以试试运行这段代码： <br />public class TestUTF8 { <br />public static void main(String[] args) throws Exception { <br />byte[][] bytes = { <br />// 00110001 <br />{(byte)0x31}, <br />// 11000000 10110001 <br />{(byte)0xC0,(byte)0xB1}, <br />// 11100000 10000000 10110001 <br />{(byte)0xE0,(byte)0x80,(byte)0xB1}, <br />// 11110000 10000000 10000000 10110001 <br />{(byte)0xF0,(byte)0x80,(byte)0x80,(byte)0xB1}, <br />// 11111000 10000000 10000000 10000000 10110001 <br />{(byte)0xF8,(byte)0x80,(byte)0x80,(byte)0x80,(byte)0xB1}, <br />// 11111100 10000000 10000000 10000000 10000000 10110001 <br />{(byte)0xFC,(byte)0x80,(byte)0x80,(byte)0x80,(byte)0x80,(byte)0xB1}, <br />}; <br />for (int i = 0; i &lt; 6; i++) { <br />String str = new String(bytes[i], "UTF-8"); <br />System.out.println("原数组长度：" + bytes[i].length + <br />"\t转换为字符串：" + str + <br />"\t转回后数组长度：" + str.getBytes("UTF-8").length); <br />} <br />} <br />} <br />运行结果为： <br />原数组长度：1 转换为字符串：1 转回后数组长度：1 <br />原数组长度：2 转换为字符串：1 转回后数组长度：1 <br />原数组长度：3 转换为字符串：1 转回后数组长度：1 <br />原数组长度：4 转换为字符串：1 转回后数组长度：1 <br />原数组长度：5 转换为字符串：1 转回后数组长度：1 <br />原数组长度：6 转换为字符串：1 转回后数组长度：1 <br /></p>
		<hr />
		<p>唉~~，看来我得加强字符编码方面的知识了！</p>
<img src ="http://www.blogjava.net/mstar/aggbug/65265.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2006-08-23 14:09 <a href="http://www.blogjava.net/mstar/archive/2006/08/23/65265.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[备份]起动SWT应用的一段程序</title><link>http://www.blogjava.net/mstar/archive/2006/06/03/50116.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Sat, 03 Jun 2006 04:54:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2006/06/03/50116.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/50116.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2006/06/03/50116.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/50116.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/50116.html</trackback:ping><description><![CDATA[做一个能知道你的SWT libraries的ClassLoader<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> SWTClassLoader </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> URLClassLoader {<br /> <br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> File workDir;<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> Set loadedLibs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HashSet();<br /> <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> SWTClassLoader(URL[] urls, File workDir) {<br />        </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">(urls);<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.workDir </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> workDir;<br />    }<br /> <br />    </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> String findLibrary(String libname) {<br />        String filename </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> System.mapLibraryName(libname);<br />        URL url </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getResource(filename);<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (url </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br /> <br />        File file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File(workDir, filename);<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">loadedLibs.contains(file))<br />            </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />                InputStream in </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> url.openStream();<br />                FileOutputStream out </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileOutputStream(file);<br />                </span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[] buf </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 0);">4096</span><span style="color: rgb(0, 0, 0);">];<br />                </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> c;<br />                </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> ((c </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> in.read(buf)) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />                    out.write(buf, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, c);<br /> <br />                out.close();<br />                loadedLibs.add(file);<br />                in.close();<br />            } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (IOException e) {<br />                </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />            } </span><span style="color: rgb(0, 0, 255);">finally</span><span style="color: rgb(0, 0, 0);"> {<br />                file.deleteOnExit();<br />            }<br /> <br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> file.getAbsolutePath();<br />    }<br />}<br /></span></div>再来个起动程序的main方法 <br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />    URL[] urls </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">URLs to your application and SWT JARs</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">;<br />    File workDir </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">working directory of your choice</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">;<br />    ClassLoader cl </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> SWTClassLoader(urls, workDir);<br />    Class mainClass </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> cl.loadClass(</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">name of your original main </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">);<br />    Method main </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> mainClass.getMethod(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">main</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Class[] { String[].</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> });<br />    main.invoke(</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Object[] { args });<br />}<br /></span></div><br /><img src ="http://www.blogjava.net/mstar/aggbug/50116.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2006-06-03 12:54 <a href="http://www.blogjava.net/mstar/archive/2006/06/03/50116.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[ZY]LinkedList vs. ArrayList</title><link>http://www.blogjava.net/mstar/archive/2006/01/26/29272.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Thu, 26 Jan 2006 12:25:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2006/01/26/29272.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/29272.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2006/01/26/29272.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/29272.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/29272.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US>LinkedList vs. ArrayList<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">今天看到的一个</SPAN><SPAN lang=EN-US>Blog</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上的内容，我把大致内容摘录下来，作为备忘。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><A href="http://javachaos.crazyredpanda.com/?p=99">http://javachaos.crazyredpanda.com/?p=99</A></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先看一下</SPAN><SPAN lang=EN-US>LinkedList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>ArrayList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的继承关系。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>public class ArrayList&lt;E&gt; extends AbstractList&lt;E&gt; implements List&lt;E&gt;, RandomAccess, Cloneable, Serializable</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>public class LinkedList&lt;E&gt; extends AbstractSequentialList&lt;E&gt; implements List&lt;E&gt;, Queue&lt;E&gt;, Cloneable, Serializable</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">两者都实现</SPAN><SPAN lang=EN-US>List</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接口，前者实现</SPAN><SPAN lang=EN-US>RandomAccess</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接口，后者实现</SPAN><SPAN lang=EN-US>Queue</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接口。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US>ArrayList<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>ArrayList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其实是包装了一个数组</SPAN><SPAN lang=EN-US> Object[]</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，当实例化一个</SPAN><SPAN lang=EN-US>ArrayList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">时，一个数组也被实例化，当向</SPAN><SPAN lang=EN-US>ArrayList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中添加对象是，数组的大小也相应的改变。这样就带来以下有缺点：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">快速随即访问</SPAN></B> <SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">你可以随即访问每个元素而不用考虑性能问题，通过调用</SPAN><SPAN lang=EN-US>get(i)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法来访问下标为</SPAN><SPAN lang=EN-US>i</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的数组元素。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">向其中添加对象速度慢</SPAN></B> <SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当你创建数组是并不能确定其容量，所以当改变这个数组时就必须在内存中做很多事情。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">操作其中对象的速度慢</SPAN></B> <SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当你要想数组中任意两个元素中间添加对象时，数组需要移动所有后面的对象。</SPAN> </P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US>LinkedList<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>LinkedList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是通过节点直接彼此连接来实现的。每一个节点都包含前一个节点的引用，后一个节点的引用和节点存储的值。当一个新节点插入时，只需要修改其中保持先后关系的节点的引用即可，当删除记录时也一样。这样就带来以下有缺点：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">操作其中对象的速度快</SPAN> </B><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">只需要改变连接，新的节点可以在内存中的任何地方</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不能随即访问</SPAN></B> <SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">虽然存在</SPAN><SPAN lang=EN-US>get()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法，但是这个方法是通过遍历接点来定位的所以速度慢。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一些结论：</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当一些被定义好的数据需要放到与数组对应的</SPAN><SPAN lang=EN-US>List</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，</SPAN><SPAN lang=EN-US>ArrayList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是很好的选择，因为它可以动态变化，但是不要在整个应用程序用频繁的使用。当你要很方便的操作其中的数据而不用随即访问时</SPAN><SPAN lang=EN-US>LinkList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是很好的选择。如果你要频繁随即访问建议使用数组。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">另外一个我没有提到的是关于</SPAN><SPAN lang=EN-US>Queue</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN><SPAN lang=EN-US>LinkedList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的实现使其具有很好的可扩展性，可以方便的在开始和结尾添加删除节点。所以</SPAN><SPAN lang=EN-US>LinkedList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">很适合用来实现</SPAN><SPAN lang=EN-US>Queue</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>Stack</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，尽管在</SPAN><SPAN lang=EN-US>Java5</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">种已经有了一个</SPAN><SPAN lang=EN-US>Stack</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的实现。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以上是原文中的观点，但是在回复中也有人反对：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>LinkedList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有以下缺陷：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象分配</SPAN><SPAN lang=EN-US>-</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">每添加一项就分配一个对象</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">回收垃圾</SPAN><SPAN lang=EN-US>-</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象分配的结果</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">随即访问慢</SPAN><SPAN lang=EN-US>-</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设计上的原因</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">添加删除慢</SPAN><SPAN lang=EN-US>-</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因为首先要找到位置</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应该使用</SPAN><SPAN lang=EN-US>LinkedList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的情况非常少。大多数的建议使使用</SPAN><SPAN lang=EN-US>LinkedList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是错误的。</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>JDK</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>Stack</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就是用数组来实现的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在多数时间里你并不是向</SPAN><SPAN lang=EN-US>List</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中间添加数据，而是向在结尾添加，这样的操作</SPAN><SPAN lang=EN-US>ArrayList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表现的很好。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>LinkedList</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在实现</SPAN><SPAN lang=EN-US>Queue</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">时很有用。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">然后是原文作者提供的一些数据：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>addFirst() to array list took 1422<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>addFirst() to linked list using general methods took 16<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>addFirst() to linked list using linked list methods took 16<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>addLast() to array list took 16<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>addLast() to linked list using general methods took 15<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>addLast() to linked list using linked list methods took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>addMiddleTest() to array list took 735<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>addMiddleTest() to linked list using general methods took 11688<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>addMiddleTest() to linked list using linked list methods took 8406<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>removeFirst() to array list took 1422<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>removeFirst() to linked list using general methods took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>removeFirst() to linked list using linked list methods took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>removeLast() to array list took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>removeLast() to linked list using general methods took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>removeLast() to linked list using linked list methods took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>removeMiddle() to array list took 734<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>removeMiddle() to linked list using general methods took 7594<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>removeMiddle() to linked list using linked list methods took 7719<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>fetchFirst() to array list took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>fetchFirst() to linked list using general methods took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>fetchFirst() to linked list using linked list methods took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>fetchLast() to array list took 16<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>fetchLast() to linked list using general methods took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>fetchLast() to linked list using linked list methods took 0<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>fetchMiddle() to array list took 15<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>fetchMiddle() to linked list using general methods took 9156<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>fetchMiddle() to linked list using linked list methods took 9234 <o:p></o:p></SPAN></P><img src ="http://www.blogjava.net/mstar/aggbug/29272.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2006-01-26 20:25 <a href="http://www.blogjava.net/mstar/archive/2006/01/26/29272.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>加载classpath中的文件</title><link>http://www.blogjava.net/mstar/archive/2005/07/20/8043.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Wed, 20 Jul 2005 06:46:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2005/07/20/8043.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/8043.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2005/07/20/8043.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/8043.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/8043.html</trackback:ping><description><![CDATA[<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; URL&nbsp;url&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.getClass().getResource(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">EJBConfig.xml</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File&nbsp;xmlFile&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;File(URLDecoder.decode(url.getFile(),</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">UTF-8</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(xmlFile.exists())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">OK</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(UnsupportedEncodingException&nbsp;e)&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">To&nbsp;change&nbsp;body&nbsp;of&nbsp;catch&nbsp;statement&nbsp;use&nbsp;File&nbsp;|&nbsp;Settings&nbsp;|&nbsp;File&nbsp;Templates.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></DIV></DIV><img src ="http://www.blogjava.net/mstar/aggbug/8043.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2005-07-20 14:46 <a href="http://www.blogjava.net/mstar/archive/2005/07/20/8043.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Random的nextInt(int i)方法的返回值</title><link>http://www.blogjava.net/mstar/archive/2005/05/21/5026.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Sat, 21 May 2005 03:04:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2005/05/21/5026.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/5026.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2005/05/21/5026.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/5026.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/5026.html</trackback:ping><description><![CDATA[docs中说返回值是从0到i，不够准确。<br>
返回值应该是 &gt;=0 , &lt;i,就是说永远也不会返回i。<br>
<img src ="http://www.blogjava.net/mstar/aggbug/5026.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2005-05-21 11:04 <a href="http://www.blogjava.net/mstar/archive/2005/05/21/5026.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>