﻿<?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-Rising Sun -随笔分类-学习总结</title><link>http://www.blogjava.net/brock/category/53326.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 25 Feb 2017 05:35:40 GMT</lastBuildDate><pubDate>Sat, 25 Feb 2017 05:35:40 GMT</pubDate><ttl>60</ttl><item><title>在同一台机器上安装多个版本jdk，修改环境变量不生效</title><link>http://www.blogjava.net/brock/archive/2015/01/06/422073.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Tue, 06 Jan 2015 03:45:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2015/01/06/422073.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/422073.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2015/01/06/422073.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/422073.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/422073.html</trackback:ping><description><![CDATA[<p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #946f34; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fff0d1;"></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp; &nbsp; 本机已经安装了jdk1.6，而比较早期的项目需要依赖jdk1.5，于是同时在本机安装了jdk1.5和jdk1.6.&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;安装jdk1.5前，执行java -version得到</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">java version "1.6.0_38"<br />Java(TM) SE Runtime Environment (build 1.6.0_38-b05)<br />Java HotSpot(TM) 64-Bit Server VM (build 20.13-b02, mixed mode)</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">安装完jdk1.5,并修改环境变量JAVA_HOME为D:\devSoftware\jdk1.5.再执行&nbsp;java -version时，依然显示：</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">java version "1.6.0_38"<br />Java(TM) SE Runtime Environment (build 1.6.0_38-b05)<br />Java HotSpot(TM) 64-Bit Server VM (build 20.13-b02, mixed mode)<br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">看上去，新的环境变量JAVA_HOME=D:\devSoftware\jdk1.5并没有生效。 在网上找了很多资料才发现：</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="text-indent: 28px;"><span style="color: #3366ff;"><strong>&nbsp; &nbsp; &nbsp; 在安装JDK1.6时（本机先安装jdk1.6再安装的jdk1.5），自动将java.exe、javaw.exe、javaws.exe三个可执行文件复制到了C:\Windows\System32目录，由于这个目录在WINDOWS环境变量中的优先级高于JAVA_HOME设置的环境变量优先级</strong></span></span><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="text-indent: 28px;"><span style="color: #3366ff;"><strong><br /></strong></span></span></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="text-indent: 28px;">解决方案：将java.exe,javaw.exe,javaws.exe删除即可。开启新的命令行窗口，再执行java -version时，就得到了期望中的结果<span style="color: #3366ff;"><strong></strong></span></span></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="text-indent: 28px;">java version "1.5.0_17"<br />Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_17-b04)<br />Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_17-b04, mixed mode)<br /></span></p><div><span style="text-indent: 28px;"><br /></span></div><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #946f34; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fff0d1; text-indent: 2em;"></p><img src ="http://www.blogjava.net/brock/aggbug/422073.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2015-01-06 11:45 <a href="http://www.blogjava.net/brock/archive/2015/01/06/422073.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> Calendar.getInstance() 不要放在循环里  当心OutOfMemoryError: Java heap space</title><link>http://www.blogjava.net/brock/archive/2014/01/08/408673.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Wed, 08 Jan 2014 03:26:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2014/01/08/408673.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/408673.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2014/01/08/408673.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/408673.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/408673.html</trackback:ping><description><![CDATA[<pre style="padding: 1em; border: 1px dashed #2f6fab; background-color: #f9f9f9; line-height: 1.1em;">  List&lt;Calendar&gt; l = new ArrayList&lt;Calendar&gt;(); <br />       while (true) {         <br />   l.add(Calendar.getInstance()); <br />           System.out.println(l.size());   <br />     }           <br />  605473   <br />     Exception in thread "main" java.lang.OutOfMemoryError: Java heap space   <br />         at java.util.Calendar.&lt;init&gt;(Unknown Source) <br />           at java.util.GregorianCalendar.&lt;init&gt;(Unknown Source)<br />            at java.util.Calendar.createCalendar(Unknown Source)<br />            at java.util.Calendar.getInstance(Unknown Source)<br />            at jodatestmemory.Main.main(Main.java:25)</pre><img src ="http://www.blogjava.net/brock/aggbug/408673.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2014-01-08 11:26 <a href="http://www.blogjava.net/brock/archive/2014/01/08/408673.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lucene空间索引</title><link>http://www.blogjava.net/brock/archive/2013/11/29/407021.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Fri, 29 Nov 2013 08:15:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/11/29/407021.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/407021.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2013/11/29/407021.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/407021.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/407021.html</trackback:ping><description><![CDATA[<div>1、创建索引 &nbsp;&nbsp;<br />-------------------------------------------------------------------------------------------<br />GeohashPrefixTree grid = new GeohashPrefixTree(ctx, 12);//&lt; 1 meter == 11 maxLevels</div><div>&nbsp; &nbsp; &nbsp; &nbsp; this.strategy = new RecursivePrefixTreeStrategy(grid, "shape");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ((RecursivePrefixTreeStrategy) this.strategy).setDistErrPct(LUCENE_4464_distErrPct);//1% radius (small!)<br /><br /><div>&nbsp;String wktstr = clobtoString(map.get("wkt"));//图形信息</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String objectid = map.get("objectid").toString();//对象id</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String name = map.get("name").toString();//对象名称</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Shape shape = wktGeoRect(wktstr);</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Document doc = new Document();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.add(new StringField("objectidtable", objectid + tableName, Field.Store.YES));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.add(new StringField("objectid", objectid, Field.Store.YES));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.add(new StringField("tableName", tableName, Field.Store.YES));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.add(new StringField("metadataid", mid.toString(), Field.Store.YES));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.add(new TextField ("title", name, Field.Store.YES));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (shape != null) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (Field f : strategy.createIndexableFields(shape)) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.add(f);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.add(new StoredField(strategy.getFieldName(), ctx.toString(shape)));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div></div><div>&nbsp; indexWriter.addDocument(doc);</div>---------------------------------------------------------------<br /><div>&nbsp; &nbsp; public Shape wktGeoRect(String wktStr) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; JtsGeometry jtsGeom = null;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; try {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (StringUtils.trim(wktStr.substring(0, wktStr.indexOf("("))).equalsIgnoreCase("POINT")) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wktStr = wktStr.substring(wktStr.indexOf("(") + 1, wktStr.lastIndexOf(")"));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String[] point = wktStr.split(" ");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ctx.makePoint(Double.parseDouble(point[0]), Double.parseDouble(point[1]));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jtsGeom = (JtsGeometry) ctx.readShape(wktStr);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception e) {</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return jtsGeom;</div><div></div><div>&nbsp; &nbsp; }</div>2、查询空间索引<br /><br /><div>&nbsp; &nbsp;@Test</div><div>&nbsp; &nbsp; public void testshape() throws Exception {</div><div></div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JtsSpatialContext ctx = JtsSpatialContext.GEO;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Directory directory = new SimpleFSDirectory(new File("D:/platform/spatiallucence"));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; IndexReader[] indexReaders1 = new IndexReader[]{IndexReader.open(directory)};</div><div>&nbsp; &nbsp; &nbsp; &nbsp; MultiReader multiReader = new MultiReader(indexReaders1);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; indexSearcher = new IndexSearcher(multiReader);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; indexSearcher.setSimilarity(new NoScoreSimilarity());</div><div>&nbsp; &nbsp; &nbsp; &nbsp; GeohashPrefixTree grid = new GeohashPrefixTree(ctx, 12);//&lt; 1 meter == 11 maxLevels</div><div>&nbsp; &nbsp; &nbsp; &nbsp; strategy = new RecursivePrefixTreeStrategy(grid, "shape");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ((RecursivePrefixTreeStrategy) strategy).setDistErrPct(0.025);//1% radius (small!)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; //POINT (121.591953019118 28.7566972164043)</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; //Shape shape = ctx.readShape("POINT (121.454715099823 28.860595871703)");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Shape shape = ctx.readShape("POLYGON(" +</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "(121.10836126349 28.84450508816,\n" +</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "121.12569906256 28.84450508816,\n" +</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "121.12569906256 28.856950537989,\n" +</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "121.10836126349 28.856950537989,\n" +</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "121.10836126349 28.84450508816))");</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; shape = ctx.makeRectangle(121.10836126349d ,121.12569906256d, 28.84450508816d ,28.856950537989d);</div><div></div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, shape);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; args.setDistErrPct(0.025);</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; Query query = strategy.makeQuery(args);</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; TopDocs results = indexSearcher.search(query, 1000);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; int numTotalHits = results.totalHits;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("共 " + numTotalHits + " 完全匹配的文档");</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; ScoreDoc[] hits = results.scoreDocs;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; hits.length; i++) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Document document = indexSearcher.doc(hits[i].doc);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Id: " + document);</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div></div><div>&nbsp; &nbsp; }</div><br /></div><img src ="http://www.blogjava.net/brock/aggbug/407021.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-11-29 16:15 <a href="http://www.blogjava.net/brock/archive/2013/11/29/407021.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java 获取cpu 使用率</title><link>http://www.blogjava.net/brock/archive/2013/08/19/403021.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Mon, 19 Aug 2013 02:40:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/08/19/403021.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/403021.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2013/08/19/403021.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/403021.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/403021.html</trackback:ping><description><![CDATA[<div>&nbsp; private static double getCpuRateForLinux(){</div><div>&nbsp; &nbsp; &nbsp; &nbsp; InputStream is = null;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; InputStreamReader isr = null;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; BufferedReader brStat = null;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; StringTokenizer tokenStat = null;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; try{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Get usage rate of CUP , linux version: "+linuxVersion);</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Process process = Runtime.getRuntime().exec("top -b -n 1");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; is = process.getInputStream();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isr = new InputStreamReader(is);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; brStat = new BufferedReader(isr);</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(linuxVersion.equals("2.4")){</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; brStat.readLine();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; brStat.readLine();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; brStat.readLine();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; brStat.readLine();</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat = new StringTokenizer(brStat.readLine());</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String user = tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String system = tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String nice = tokenStat.nextToken();</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(user+" , "+system+" , "+nice);</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user = user.substring(0,user.indexOf("%"));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system = system.substring(0,system.indexOf("%"));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nice = nice.substring(0,nice.indexOf("%"));</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float userUsage = new Float(user).floatValue();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float systemUsage = new Float(system).floatValue();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float niceUsage = new Float(nice).floatValue();</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return (userUsage+systemUsage+niceUsage)/100;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; brStat.readLine();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; brStat.readLine();</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat = new StringTokenizer(brStat.readLine());</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tokenStat.nextToken();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String cpuUsage = tokenStat.nextToken();</div><div></div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("CPU idle : "+cpuUsage);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Float usage = new Float(cpuUsage.substring(0,cpuUsage.indexOf("%")));</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return (1-usage.floatValue()/100);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div></div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; } catch(IOException ioe){</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(ioe.getMessage());</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; freeResource(is, isr, brStat);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 1;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; } finally{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; freeResource(is, isr, brStat);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div></div><div>&nbsp; &nbsp; }</div><div>&nbsp; &nbsp; private static void freeResource(InputStream is, InputStreamReader isr, BufferedReader br){</div><div>&nbsp; &nbsp; &nbsp; &nbsp; try{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(is!=null)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; is.close();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(isr!=null)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isr.close();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(br!=null)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; br.close();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }catch(IOException ioe){</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(ioe.getMessage());</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; }</div><div></div><div></div><div>&nbsp; &nbsp; /**</div><div>&nbsp; &nbsp; &nbsp;* 获得CPU使用率. &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp;* @return 返回cpu使用率</div><div>&nbsp; &nbsp; &nbsp;* @author GuoHuang</div><div>&nbsp; &nbsp; &nbsp;*/</div><div>&nbsp; &nbsp; private double getCpuRatioForWindows() {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; try {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String procCmd = System.getenv("windir")</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + "\\system32\\wbem\\wmic.exe process get Caption,CommandLine,"</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + "KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 取进程信息 &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long[] c0 = readCpu(Runtime.getRuntime().exec(procCmd));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.sleep(CPUTIME);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long[] c1 = readCpu(Runtime.getRuntime().exec(procCmd));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (c0 != null &amp;&amp; c1 != null) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long idletime = c1[0] - c0[0];</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long busytime = c1[1] - c0[1];</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Double.valueOf(</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PERCENT * (busytime) / (busytime + idletime))</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .doubleValue();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0.0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception ex) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex.printStackTrace();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0.0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; }</div><div></div><div>&nbsp; &nbsp; /**</div><div></div><div>&nbsp; &nbsp; &nbsp;* 读取CPU信息.</div><div>&nbsp; &nbsp; &nbsp;* @param proc</div><div>&nbsp; &nbsp; &nbsp;* @return</div><div>&nbsp; &nbsp; &nbsp;* @author GuoHuang</div><div>&nbsp; &nbsp; &nbsp;*/</div><div>&nbsp; &nbsp; private long[] readCpu(final Process proc) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; long[] retn = new long[2];</div><div>&nbsp; &nbsp; &nbsp; &nbsp; try {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proc.getOutputStream().close();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InputStreamReader ir = new InputStreamReader(proc.getInputStream());</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LineNumberReader input = new LineNumberReader(ir);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String line = input.readLine();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (line == null || line.length() &lt; FAULTLENGTH) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return null;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int capidx = line.indexOf("Caption");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int cmdidx = line.indexOf("CommandLine");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int rocidx = line.indexOf("ReadOperationCount");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int umtidx = line.indexOf("UserModeTime");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int kmtidx = line.indexOf("KernelModeTime");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int wocidx = line.indexOf("WriteOperationCount");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long idletime = 0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long kneltime = 0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long usertime = 0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ((line = input.readLine()) != null) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (line.length() &lt; wocidx) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 字段出现顺序：Caption,CommandLine,KernelModeTime,ReadOperationCount, &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ThreadCount,UserModeTime,WriteOperation &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String caption = Bytes.substring(line, capidx, cmdidx - 1)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .trim();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String cmd = Bytes.substring(line, cmdidx, kmtidx - 1).trim();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (cmd.indexOf("wmic.exe") &gt;= 0) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // log.info("line="+line); &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (caption.equals("System Idle Process")</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; || caption.equals("System")) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; idletime += Long.valueOf(</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bytes.substring(line, kmtidx, rocidx - 1).trim())</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .longValue();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; idletime += Long.valueOf(</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bytes.substring(line, umtidx, wocidx - 1).trim())</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .longValue();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kneltime += Long.valueOf(</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bytes.substring(line, kmtidx, rocidx - 1).trim())</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .longValue();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; usertime += Long.valueOf(</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bytes.substring(line, umtidx, wocidx - 1).trim())</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .longValue();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; retn[0] = idletime;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; retn[1] = kneltime + usertime;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return retn;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception ex) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex.printStackTrace();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; } finally {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proc.getInputStream().close();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception e) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return null;</div><div>&nbsp; &nbsp; }<br /><span style="color: red; ">上面方法不行，下面的可以</span><br /><div>&nbsp; String result = "";</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; try {</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; File file = File.createTempFile("tmp", ".vbs");</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file.deleteOnExit();</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileWriter fw = new java.io.FileWriter(file);</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String vbs ="Set objProc = GetObject(\"winmgmts:\\\\.\\root\\cimv2:win32_processor='cpu0'\")\n" +</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "WScript.Echo &nbsp;\"CPU Load Percentage: \"&amp; chr(13) &amp; chr(10) &amp; Round(objProc.LoadPercentage,2) &amp; \"%\"";</div><div></div><div></div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fw.write(vbs);</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fw.close();</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String line;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ((line = input.readLine()) != null) {</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result += line;</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input.close();</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file.delete();</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception e) {</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.fillInStackTrace();</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; if (result.trim().length() &lt; 1 || result == null) {</div><div></div><div></div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; }else{</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(result.trim());</div><div></div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><br /><br /><br /><br /></div><img src ="http://www.blogjava.net/brock/aggbug/403021.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-08-19 10:40 <a href="http://www.blogjava.net/brock/archive/2013/08/19/403021.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java 注册到 windows 服务</title><link>http://www.blogjava.net/brock/archive/2013/08/09/402627.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Fri, 09 Aug 2013 06:20:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/08/09/402627.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/402627.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2013/08/09/402627.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/402627.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/402627.html</trackback:ping><description><![CDATA[<div>#encoding=UTF-8</div><div># Configuration files must begin with a line specifying the encoding</div><div># &nbsp;of the the file.</div><div></div><div>#********************************************************************</div><div># Wrapper License Properties (Ignored by Community Edition)</div><div>#********************************************************************</div><div># Professional and Standard Editions of the Wrapper require a valid</div><div># &nbsp;License Key to start. &nbsp;Licenses can be purchased or a trial license</div><div># &nbsp;requested on the following pages:</div><div># http://wrapper.tanukisoftware.com/purchase</div><div># http://wrapper.tanukisoftware.com/trial</div><div></div><div># Include file problems can be debugged by removing the first '#'</div><div># &nbsp;from the following line:</div><div>##include.debug</div><div></div><div># The Wrapper will look for either of the following optional files for a</div><div># &nbsp;valid License Key. &nbsp;License Key properties can optionally be included</div><div># &nbsp;directly in this configuration file.</div><div>#include ../conf/wrapper-license.conf</div><div>#include ../conf/wrapper-license-%WRAPPER_HOST_NAME%.conf</div><div></div><div># The following property will output information about which License Key(s)</div><div># &nbsp;are being found, and can aid in resolving any licensing problems.</div><div>#wrapper.license.debug=TRUE</div><div></div><div>#********************************************************************</div><div># Wrapper Localization</div><div>#********************************************************************</div><div># Specify the locale which the Wrapper should use. &nbsp;By default the system</div><div># &nbsp;locale is used.</div><div>#wrapper.lang=en_US # en_US or ja_JP</div><div></div><div># Specify the location of the Wrapper's language resources. &nbsp;If these are</div><div># &nbsp;missing, the Wrapper will default to the en_US locale.</div><div>wrapper.lang.folder=../lang</div><div></div><div>#********************************************************************</div><div># Wrapper Java Properties</div><div>#********************************************************************</div><div># Java Application</div><div># &nbsp;Locate the java binary on the system PATH:</div><div>wrapper.java.command=java</div><div># &nbsp;Specify a specific java binary:</div><div>#set.JAVA_HOME=/java/path</div><div>set.LIB=D:/MonitorApp/lib</div><div>#wrapper.java.command=%JAVA_HOME%/bin/java</div><div></div><div># Tell the Wrapper to log the full generated Java command line.</div><div>#wrapper.java.command.loglevel=INFO</div><div></div><div># Java Main class. &nbsp;This class must implement the WrapperListener interface</div><div># &nbsp;or guarantee that the WrapperManager class is initialized. &nbsp;Helper</div><div># &nbsp;classes are provided to do this for you. &nbsp;See the Integration section</div><div># &nbsp;of the documentation for details.</div><div>wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp</div><div></div><div># Java Classpath (include wrapper.jar) &nbsp;Add class path elements as</div><div># &nbsp;needed starting from 1</div><div></div><div>echo %LIB%</div><div></div><div>wrapper.java.classpath.1=%LIB%/wrapper.jar</div><div>wrapper.java.classpath.2=%LIB%/commons-beanutils-1.8.3.jar</div><div>wrapper.java.classpath.3=%LIB%/commons-codec-1.4.jar</div><div>wrapper.java.classpath.4=%LIB%/commons-collections-3.1.jar</div><div>wrapper.java.classpath.5=%LIB%/commons-collections-3.2.1.jar</div><div>wrapper.java.classpath.6=%LIB%/commons-dbcp-1.3.jar</div><div>wrapper.java.classpath.7=%LIB%/commons-dbcp-1.4.jar</div><div>wrapper.java.classpath.8=%LIB%/commons-fileupload-1.2.1.jar</div><div>wrapper.java.classpath.9=%LIB%/commons-httpclient-3.0.1.jar</div><div>wrapper.java.classpath.10=%LIB%/commons-io-1.4.jar</div><div>wrapper.java.classpath.11=%LIB%/commons-io-2.0.1.jar</div><div>wrapper.java.classpath.12=%LIB%/commons-jexl-1.1.jar</div><div>wrapper.java.classpath.13=%LIB%/commons-lang-2.5.jar</div><div>wrapper.java.classpath.14=%LIB%/commons-logging-1.1.1.jar</div><div>wrapper.java.classpath.15=%LIB%/commons-logging-api-1.1.jar</div><div>wrapper.java.classpath.16=%LIB%/commons-management-1.0.jar</div><div>wrapper.java.classpath.17=%LIB%/commons-pool-1.5.4.jar</div><div>wrapper.java.classpath.18=%LIB%/jedis-2.0.0.jar</div><div>wrapper.java.classpath.19=%LIB%/log4j-1.2.14.jar</div><div>wrapper.java.classpath.20=%LIB%/quartz-all-1.6.3.jar</div><div>wrapper.java.classpath.21=%LIB%/spring-aop-3.0.2.RELEASE.jar</div><div>wrapper.java.classpath.22=%LIB%/spring-asm-3.0.2.RELEASE.jar</div><div>wrapper.java.classpath.23=%LIB%/spring-beans-3.0.2.RELEASE.jar</div><div>wrapper.java.classpath.24=%LIB%/spring-binding-2.0.8.RELEASE.jar</div><div>wrapper.java.classpath.25=%LIB%/spring-context-3.0.2.RELEASE.jar</div><div>wrapper.java.classpath.26=%LIB%/spring-context-support-3.0.2.RELEASE.jar</div><div>wrapper.java.classpath.27=%LIB%/spring-core-3.0.2.RELEASE.jar</div><div>wrapper.java.classpath.28=%LIB%/spring-expression-3.0.2.RELEASE.jar</div><div>wrapper.java.classpath.29=%LIB%/springside-3.3.2.jar</div><div>wrapper.java.classpath.30=%LIB%/spring-test-3.0.2.RELEASE.jar</div><div>wrapper.java.classpath.31=%LIB%/spring-tx-3.0.2.RELEASE.jar</div><div>wrapper.java.classpath.32=%LIB%/slf4j-api-1.5.8.jar</div><div>wrapper.java.classpath.33=%LIB%/slf4j-log4j12-1.5.8.jar</div><div>wrapper.java.classpath.34=%LIB%/monitor.jar<br /></div><div><span style="color: red; ">wrapper.java.classpath.35=%LIB% &nbsp; #可以读到这里的文件 xml pro 等 &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div></div><div># Java Library Path (location of Wrapper.DLL or libwrapper.so)</div><div>wrapper.java.library.path.1=../bin</div><div></div><div># Java Bits. &nbsp;On applicable platforms, tells the JVM to run in 32 or 64-bit mode.</div><div>wrapper.java.additional.auto_bits=TRUE</div><div></div><div># Java Additional Parameters</div><div>wrapper.java.additional.1=-Dlog4j.configuration=file:%LIB%/log4j.xml</div><div>wrapper.java.additional.2=-Dorg.tanukisoftware.wrapper.WrapperManager.mbean=TRUE</div><div></div><div># Initial Java Heap Size (in MB)</div><div>wrapper.java.initmemory=128</div><div></div><div># Maximum Java Heap Size (in MB)</div><div>wrapper.java.maxmemory=512</div><div></div><div># Application parameters. &nbsp;Add parameters as needed starting from 1</div><div>wrapper.app.parameter.1=com.zjasm.tomcat.TomcatStat</div><div></div><div>#********************************************************************</div><div># Wrapper Logging Properties</div><div>#********************************************************************</div><div># Enables Debug output from the Wrapper.</div><div>#wrapper.debug=TRUE</div><div></div><div># Format of output for the console. &nbsp;(See docs for formats)</div><div>wrapper.console.format=PM</div><div></div><div># Log Level for console output. &nbsp;(See docs for log levels)</div><div>wrapper.console.loglevel=INFO</div><div></div><div># Log file to use for wrapper output logging.</div><div>wrapper.logfile=../logs/wrapper.log</div><div></div><div># Format of output for the log file. &nbsp;(See docs for formats)</div><div>wrapper.logfile.format=LPTM</div><div></div><div># Log Level for log file output. &nbsp;(See docs for log levels)</div><div>wrapper.logfile.loglevel=INFO</div><div></div><div># Maximum size that the log file will be allowed to grow to before</div><div># &nbsp;the log is rolled. Size is specified in bytes. &nbsp;The default value</div><div># &nbsp;of 0, disables log rolling. &nbsp;May abbreviate with the 'k' (kb) or</div><div># &nbsp;'m' (mb) suffix. &nbsp;For example: 10m = 10 megabytes.</div><div>wrapper.logfile.maxsize=0</div><div></div><div># Maximum number of rolled log files which will be allowed before old</div><div># &nbsp;files are deleted. &nbsp;The default value of 0 implies no limit.</div><div>wrapper.logfile.maxfiles=0</div><div></div><div># Log Level for sys/event log output. &nbsp;(See docs for log levels)</div><div>wrapper.syslog.loglevel=NONE</div><div></div><div>#********************************************************************</div><div># Wrapper General Properties</div><div>#********************************************************************</div><div># Allow for the use of non-contiguous numbered properties</div><div>wrapper.ignore_sequence_gaps=TRUE</div><div></div><div># Do not start if the pid file already exists.</div><div>wrapper.pidfile.strict=TRUE</div><div></div><div># Title to use when running as a console</div><div>wrapper.console.title=Test Wrapper Sample Application</div><div></div><div>#********************************************************************</div><div># Wrapper JVM Checks</div><div>#********************************************************************</div><div># Detect DeadLocked Threads in the JVM. (Requires Standard Edition)</div><div>wrapper.check.deadlock=TRUE</div><div>wrapper.check.deadlock.interval=10</div><div>wrapper.check.deadlock.action=RESTART</div><div>wrapper.check.deadlock.output=FULL</div><div></div><div># Out Of Memory detection.</div><div># (Ignore output from dumping the configuration to the console. &nbsp;This is only needed by the TestWrapper sample application.)</div><div>wrapper.filter.trigger.999=wrapper.filter.trigger.*java.lang.OutOfMemoryError</div><div>wrapper.filter.allow_wildcards.999=TRUE</div><div>wrapper.filter.action.999=NONE</div><div># &nbsp;Ignore -verbose:class output to avoid false positives.</div><div>wrapper.filter.trigger.1000=[Loaded java.lang.OutOfMemoryError</div><div>wrapper.filter.action.1000=NONE</div><div># (Simple match)</div><div>wrapper.filter.trigger.1001=java.lang.OutOfMemoryError</div><div># (Only match text in stack traces if -XX:+PrintClassHistogram is being used.)</div><div>#wrapper.filter.trigger.1001=Exception in thread "*" java.lang.OutOfMemoryError</div><div>#wrapper.filter.allow_wildcards.1001=TRUE</div><div>wrapper.filter.action.1001=RESTART</div><div>wrapper.filter.message.1001=The JVM has run out of memory.</div><div></div><div>#********************************************************************</div><div># Wrapper Email Notifications. (Requires Professional Edition)</div><div>#********************************************************************</div><div># Common Event Email settings.</div><div>#wrapper.event.default.email.debug=TRUE</div><div>#wrapper.event.default.email.smtp.host=&lt;SMTP_Host&gt;</div><div>#wrapper.event.default.email.smtp.port=25</div><div>#wrapper.event.default.email.subject=[%WRAPPER_HOSTNAME%:%WRAPPER_NAME%:%WRAPPER_EVENT_NAME%] Event Notification</div><div>#wrapper.event.default.email.sender=&lt;Sender email&gt;</div><div>#wrapper.event.default.email.recipient=&lt;Recipient email&gt;</div><div></div><div># Configure the log attached to event emails.</div><div>#wrapper.event.default.email.attach_log=TRUE</div><div>#wrapper.event.default.email.maillog.lines=50</div><div>#wrapper.event.default.email.maillog.format=LPTM</div><div>#wrapper.event.default.email.maillog.loglevel=INFO</div><div></div><div># Enable specific event emails.</div><div>#wrapper.event.wrapper_start.email=TRUE</div><div>#wrapper.event.jvm_prelaunch.email=TRUE</div><div>#wrapper.event.jvm_start.email=TRUE</div><div>#wrapper.event.jvm_started.email=TRUE</div><div>#wrapper.event.jvm_deadlock.email=TRUE</div><div>#wrapper.event.jvm_stop.email=TRUE</div><div>#wrapper.event.jvm_stopped.email=TRUE</div><div>#wrapper.event.jvm_restart.email=TRUE</div><div>#wrapper.event.jvm_failed_invocation.email=TRUE</div><div>#wrapper.event.jvm_max_failed_invocations.email=TRUE</div><div>#wrapper.event.jvm_kill.email=TRUE</div><div>#wrapper.event.jvm_killed.email=TRUE</div><div>#wrapper.event.jvm_unexpected_exit.email=TRUE</div><div>#wrapper.event.wrapper_stop.email=TRUE</div><div></div><div># Specify custom mail content</div><div>wrapper.event.jvm_restart.email.body=The JVM was restarted.\n\nPlease check on its status.\n</div><div></div><div>#********************************************************************</div><div># Wrapper Windows NT/2000/XP Service Properties</div><div>#********************************************************************</div><div># WARNING - Do not modify any of these properties when an application</div><div># &nbsp;using this configuration file has been installed as a service.</div><div># &nbsp;Please uninstall the service before modifying this section. &nbsp;The</div><div># &nbsp;service can then be reinstalled.</div><div></div><div># Name of the service</div><div>wrapper.name=testwrapper</div><div></div><div># Display name of the service</div><div>wrapper.displayname=Test Wrapper Sample Application</div><div></div><div># Description of the service</div><div>wrapper.description=Test Wrapper Sample Application Description</div><div></div><div># Service dependencies. &nbsp;Add dependencies as needed starting from 1</div><div>wrapper.ntservice.dependency.1=</div><div></div><div># Mode in which the service is installed. &nbsp;AUTO_START, DELAY_START or DEMAND_START</div><div>wrapper.ntservice.starttype=AUTO_START</div><div></div><div># Allow the service to interact with the desktop.</div><div>wrapper.ntservice.interactive=false</div><div></div><img src ="http://www.blogjava.net/brock/aggbug/402627.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-08-09 14:20 <a href="http://www.blogjava.net/brock/archive/2013/08/09/402627.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>哥把Tengine改回NGINX</title><link>http://www.blogjava.net/brock/archive/2013/05/16/399366.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Thu, 16 May 2013 08:54:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/05/16/399366.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/399366.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2013/05/16/399366.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/399366.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/399366.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: http://vc.hsly0559.cn/c/20111216_957.html首先，马云坑到了很多钱。。。所以确实有一批大神在为他干活　　其次，现在阿里系出来又是出书又是演讲跳大神装B。。不是牛人。。给我的感觉。。跳梁小丑一样，给后端的牛人抹黑,我实在看不习惯　　第三，最近关于Tengine的讨论很火，简单看了下，在大流量下确实表现不错，而且据说可以过滤掉一些攻击或类似攻击流量，这是其宣称的特...&nbsp;&nbsp;<a href='http://www.blogjava.net/brock/archive/2013/05/16/399366.html'>阅读全文</a><img src ="http://www.blogjava.net/brock/aggbug/399366.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-05-16 16:54 <a href="http://www.blogjava.net/brock/archive/2013/05/16/399366.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于产品经理的四点思考</title><link>http://www.blogjava.net/brock/archive/2013/03/22/396844.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Fri, 22 Mar 2013 03:16:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/03/22/396844.html</guid><description><![CDATA[<p style="line-height:18.0pt;background:#F8F7F5"><span style="font-family:&quot;Helvetica&quot;,&quot;sans-serif&quot;;color:#3E3E3E">1 </span><span style="color:#3E3E3E">做产品经理，而不是功能经理；</span></p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-family:&quot;Helvetica&quot;,&quot;sans-serif&quot;;color:#3E3E3E">2 </span><span style="color:#3E3E3E">做产品需求，而不是用户需求；</span></p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="color:#3E3E3E">3&nbsp;</span><span style="color:#3E3E3E">要锦上添花，而不是画蛇添足；</span></p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="color:#3E3E3E">4&nbsp;</span><span style="color:#3E3E3E">追求人性化，而不是追求完美。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">产品经理是个很奇怪的岗位，好像大多数人都能做，因为每个人对某个产品都有自己的看法，都能提出一些意见和想法，甚至能设计实现原理；也好像大多数人都做不好产品经理，因为互联网上成千上万个产品，大部分是垃圾，没几个产品是用户真心觉得很不错的。</span></p>  <p style="margin: 0cm 0cm 0.0001pt; line-height: 18pt; background-color: #f8f7f5; min-height: 1.5em; orphans: 2; widows: 2; background-position: initial initial; background-repeat: initial initial;">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">我做产品经理，还不到两年，以前十来年一直在做技术。之前做技术的时候，我很看不上产品经理。当时想：产品经理自己什么都实现不了，每天就是提点想法，而且想法还经常不靠谱，如果哪天裁员，产品经理的位置最危险了；但等我转来做了产品经理，想法发生了根本的变化：嗯，产品经理太重要的，一个产品的未来就决定在产品经理身上。</span></p>  <p style="margin: 0cm 0cm 0.0001pt; line-height: 18pt; background-color: #f8f7f5; min-height: 1.5em; orphans: 2; widows: 2; background-position: initial initial; background-repeat: initial initial;">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">你问我现在如何看待技术人员？嘿嘿，我现在觉得，技术就是一把刀，让它杀谁就杀谁！当然，这只是开玩笑。一个好的技术团队对于产品经理来说，那是相当重要。</span></p>  <p style="margin: 0cm 0cm 0.0001pt; line-height: 18pt; background-color: #f8f7f5; min-height: 1.5em; orphans: 2; widows: 2; background-position: initial initial; background-repeat: initial initial;">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">对如何做产品经理，我还真的是小学生，自己负责的淘宝搜索最近两年也没什么大提升。特别是看了周鸿祎、张小龙关于对产品的一些访谈以后，我更发现自己在这方面的差距。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">不过我有个优点，就是善于学习、思考、总结并分享。而且作为一个外行进入到这个领域，观察的角度也会不一样。这一年多下来，也找到一些感觉，发现周围的一些产品经理，容易走入一些误区，分享给大家。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">1&nbsp;</span><span style="font-size:13.5pt;color:#3E3E3E">做产品经理，而不是功能经理。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">这句话我最早是听天猫总裁逍遥子说的，当时没有感觉，现在发现非常有道理，因为周围太多的产品经理实际上是在做一名功能经理。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">他们只是不停的在接产品功能需求，然后不停实现产品功能。缺登录，设计一个登录框；没有数据，找某个平台打通一下；管理不方便，设计一个工具来管理；页面不美观，重新规划一下页面结构&#8230;&#8230;</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">功能经理，每天都很忙，关注还有多少需求在后面排队，需求方是否得到满足。而用户体验到底如何，功能是否真的真有价值，是否可以更加完美，功能经理很少关心。当有人抱怨某个功能不爽的时候，他会说：</span></p>  <p style="line-height:18.0pt;background:#F8F7F5"><strong><span style="font-size:13.5pt;font-family:宋体;color:#3E3E3E">这个功能我已经有了啊，你说体验不太好？没办法，工程师资源太紧张啊，你说为啥设计的这么别扭？kao，想起来就来气，大老板非要求这样啊，我们也只能这样设计，没办法！</span></strong></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">他经常表达的语气是他也不得已而为之，把责任都推到其他人身上。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">然而做一个合格的产品经理，需要关注用户的体验，真正关注用户的反馈，关注数据的质量，关注每一个细节。就像买一双鞋一样，不只是能穿，还要考虑是否合脚，是否舒服，款式是否漂亮。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">有一次开会，淘宝的总裁语嫣姐姐说了一句很朴素但很有道理的一句话：产品能用和好用完全不是一回事！</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">(</span><span style="font-size:13.5pt;color:#3E3E3E">大家不用批评淘宝搜索啊，我知道很多地方还不好用。大家再给我点时间，我也认识到这个问题不是......)</span></p>  <p style="margin: 0cm 0cm 0.0001pt; line-height: 18pt; background-color: #f8f7f5; min-height: 1.5em; orphans: 2; widows: 2; background-position: initial initial; background-repeat: initial initial;">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">2&nbsp;</span><span style="font-size:13.5pt;color:#3E3E3E">实现产品需求，而不是用户需求。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">这个话题很有意思。当你问用户需要什么的时候，他会回答他需要一匹更快的马。乔布斯说，永远不要问用户想要什么！因为用户都是傻瓜，不知道自己想要什么。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">这其实是产品经理经常把用户需求当成产品需求。对所有用户说的，他们没错，提的都是自己的期望，不是一个产品需求。前些天有张小龙的采访，张小龙说他不看用户的数据。其实张小龙很关心用户的需求，我和张小龙在一个群里，如果有人在群里提一些微信使用不爽的功能，张小龙会很快给出反馈。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">这些产品大神们，背后的意思是，不应该简单满足用户需求，而应该思考把用户需求提炼成产品需求。当一个产品的用户有上百万上千万的时候，产品需求的理解和提炼，就相当重要。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">这个道理比较容易理解，不做多解释。</span></p>  <p style="margin: 0cm 0cm 0.0001pt; line-height: 18pt; background-color: #f8f7f5; min-height: 1.5em; orphans: 2; widows: 2; background-position: initial initial; background-repeat: initial initial;">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">3&nbsp;</span><span style="font-size:13.5pt;color:#3E3E3E">要锦上添花，而不是画蛇添足。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">互联网的发展，让很多互联网产品经理有个惯性：做产品迭代要快。快速上线，快速修改。这里也有误区，对于一些基本功能，确实要快速上线，快速迭代。因为有市场竞争，需要快速切入市场，获得用户。然而大部分的产品经理，没有机会从零开始设计一个新产品，大部分时候在现有的产品上做升级或优化。这时设计的很多功能，都是锦上添花的功能，还真不能太快。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">锦上添花的功能，同样重要，会让产品更好玩，更有意思，更有特点。例如微信最早设计的摇一摇功能、朋友圈功能。微博的微刊功能、之前的送礼物的功能。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">问题在于，锦上添花，添上去的一定是一朵花，说得俗一点，不能添上去是一坨屎。如果是后者，那么就有点画蛇添足了，或者成了鸡肋功能。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">什么是一朵花？就是功能添加上去以后，会让用户眼前一亮。给人有&#8220;哇！！！&#8221;的感觉&#8230;&#8230;</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">遗憾的是淘宝搜索之前的很多功能添上去的都不是一朵花，上线了太多的画蛇添足的功能。这些功能一旦上线，就很难下线。因为当你产品的用户群有上亿的时候，再烂的一个功能，每天也会有几十万用户在使用。一旦你下线，会有很多人很不爽。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">淘宝搜索的同店购就有点这个味道。技术实现成本高，体验一般，用的人也不多。有一段时间我们把这个功能隐藏起来了，有人在微博上说：</span></p>  <p style="line-height:18.0pt;background:#F8F7F5"><strong><span style="font-size:13.5pt;font-family:宋体;color:#3E3E3E">妈的，我现在最想做的事情，就是找把刀杀个淘宝搜索的产品经理来解解恨，我居然死活找不到我最常用的同店购了！</span></strong></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">画蛇添足的功能越多，让产品背负的垃圾就越多，造成好的功能没有资源做，差的功能又无法下线。</span></p>  <p style="margin: 0cm 0cm 0.0001pt; line-height: 18pt; background-color: #f8f7f5; min-height: 1.5em; orphans: 2; widows: 2; background-position: initial initial; background-repeat: initial initial;">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">4&nbsp;</span><span style="font-size:13.5pt;color:#3E3E3E">追求人性化，而不是追求完美。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">很多产品经理，追求完美。这是作为产品经理很好的品质，然而，有一点却经常被产品经理忽视，产品的人性化。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">永远没有完美的产品，特别是当一个产品的用户量到达上百万上千万的时候。用户的喜好千差万别。如何让用户能喜欢产品的优点的同时能容忍产品的缺点？</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">大家看选美大赛获胜的美女，经常会有感叹，为什么这么丑还能得前三啊！是因为评委的口味太特别？当然有一部分评委原因，但更多原因在于，大家每个人的审美观不一样。大家是把选美冠军作为一个完美的人来评判。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">实际上，无论选出谁是冠军，都会有人觉得难看。任何一个产品，无论产品经理推出多么好用的功能，都会有人不喜欢！</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">然而，大家对待周围的朋友，就不会用选美的标准要求他们，他们有明显的缺点，但也有很多值得欣赏的地方。大家订阅鬼脚七的微信，绝大部分人不会期望，鬼脚七每天的文章都会符合自己的口味。有人不看文章，只看看【7哥闲谈】也会觉得很有意思。为什么？因为大家不会期待鬼脚七这个账号是个完美的账号，把鬼脚七作为一个朋友在看待。鬼脚七有缺点，也有优点。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">如果能让用户把我们的产品当成周围的朋友来看待呢？感觉会完全不一样。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">淘宝有个做运营的同事有一天跟我感叹说：我忽然觉得攻城狮们离我好近，每个攻城狮内心都住着个诗人！我问为什么会忽然有这种感觉？她说有一天晚上，发现在淘宝内部一个TMS系统的标题栏上忽然多了一句话：</span></p>  <p style="line-height:18.0pt;background:#F8F7F5"><strong><span style="font-size:13.5pt;font-family:宋体;color:#3E3E3E">每个人的压力，少部分来自生存，大部分来自攀比。</span></strong></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">就这一句话，让用户感觉到了产品背后的那位工程师。还记得微信有个版本的欢迎页面上的文字吗：</span></p>  <p style="line-height:18.0pt;background:#F8F7F5"><strong><span style="font-size:13.5pt;font-family:宋体;color:#3E3E3E">少发微信，多和朋友见见面！</span></strong></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">就这一句话，让我感觉到产品背后的那群人的心理活动。微信的一些小瑕疵，我也能容忍。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">就是这句话，我喜欢上了微信。</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">人性化，是不是让产品开始具有了灵魂？</span></p>  <p style="line-height:18.0pt;background:#F8F7F5">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">如何让产品更加人性化？如何让淘宝搜索更加人性化？是我最近一直在思考的问题。我定义2013年搜索的关键词：专业和有趣。希望2013年能让更多的人把淘宝搜索当成一个朋友，而不是一个工具。</span></p>  <p style="margin: 0cm 0cm 0.0001pt; line-height: 18pt; background-color: #f8f7f5; min-height: 1.5em; orphans: 2; widows: 2; background-position: initial initial; background-repeat: initial initial;">&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><span style="font-size:13.5pt;color:#3E3E3E">写了这么多，回头看看我这篇文章，好像没有什么产品设计方法，只是一些思考，仅此而已。</span></p>  <p>&nbsp;</p>  <p style="line-height:18.0pt;background:#F8F7F5"><strong><span style="font-size:10.5pt;font-family:宋体;color:#3E3E3E">作者介绍：</span></strong></p>  <p style="line-height:18.0pt;background:#F8F7F5"><strong><span style="font-size:10.5pt;font-family:宋体;color:#3E3E3E">鬼脚七，一个简单的人，分享电商资讯、搜索变化、淘宝动态、产品设计、管理心得、生活感悟；偶尔文艺，偶尔深沉。做一个有思想的人！微信账号</span></strong><strong><span style="font-size:10.5pt;font-family:&quot;Helvetica&quot;,&quot;sans-serif&quot;; color:#3E3E3E">: taobaoguijiaoqi </span></strong><strong><span style="font-size:10.5pt;font-family:宋体;color:#3E3E3E">加为好友后回复</span></strong><strong><span style="font-size:10.5pt;font-family:&quot;Helvetica&quot;,&quot;sans-serif&quot;; color:#3E3E3E"> m </span></strong><strong><span style="font-size:10.5pt; font-family:宋体;color:#3E3E3E">可以看到作者之前的所有文章。</span></strong></p><img src ="http://www.blogjava.net/brock/aggbug/396844.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-03-22 11:16 <a href="http://www.blogjava.net/brock/archive/2013/03/22/396844.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Servlet生命周期</title><link>http://www.blogjava.net/brock/archive/2013/03/05/396076.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Tue, 05 Mar 2013 06:09:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/03/05/396076.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/396076.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2013/03/05/396076.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/396076.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/396076.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><div>http://sunnylocus.iteye.com/blog/342996</div>&nbsp; &nbsp;大多数程序员都知道Servlet的生命周期，简单的概括这就分为四步：servlet类加载---&gt;实例化---&gt;服务---&gt;销毁。对这个过程只是肤浅了解下，对于servlet何时被销毁，还是不太情楚。下面我们描述一下Tomcat与Servlet是如何工作的,首先看下面的时序图.</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><img width="700" alt="" src="http://sunnylocus.iteye.com/upload/picture/pic/32447/6e4a2336-7c0b-33b3-b4f7-6fc7cb51f5ea.jpg" height="366" title="点击查看原始大小图片" style="border: 0px; cursor: url(http://www.iteye.com/images/magplus.gif), pointer;" /></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">1、Web Client 向Servlet容器（Tomcat）发出Http请求</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">2、Servlet容器接收Web Client的请求</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">3、Servlet容器创建一个HttpRequest对象，将Web Client请求的信息封装到这个对象中</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">4、Servlet容器创建一个HttpResponse对象</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">5、Servlet容器调用HttpServlet对象的service方法，把HttpRequest对象与HttpResponse对象作为参数</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">&nbsp;&nbsp;&nbsp;&nbsp; 传给 HttpServlet对象</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">6、HttpServlet调用HttpRequest对象的有关方法，获取Http请求信息</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">7、HttpServlet调用HttpResponse对象的有关方法，生成响应数据</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">8、Servlet容器把HttpServlet的响应结果传给Web Client</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">对于Servlet容器(Tomcat)与HttpServlet是怎样进行交互的呢，看下类图</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><img width="672" alt="" src="http://sunnylocus.iteye.com/upload/picture/pic/32449/45a5f265-329f-3400-ab54-935f2d59f9bb.jpg" height="420" style="border: 0px;" /></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">Servlet的框架是由两个Java包组成的：javax.servlet与javax.servlet.http。在javax.servlet包中定义了所有的Servlet类都必须实现或者扩展的通用接口和类。在javax.servlet.http包中定义了采用Http协议通信的HttpServlet类。Servlet的框架的核心是javax.servlet.Servlet接口，所有的Servlet都必须实现这个接口。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">在Servlet接口中定义了5个方法，</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">其中3个方法代表了Servlet的生命周期：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">1、init方法：负责初始化Servlet对象。</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">2、service方法：负责响应客户的请求。</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="color: #ff0000;">3、destroy方法：当Servlet对象退出生命周期时，负责释放占用的资源。</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><strong>一、创建Servlet对象的时机</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">1、Servlet容器启动时：读取web.xml配置文件中的信息，构造指定的Servlet对象，创建ServletConfig对象，同时将ServletConfig对象作为参数来调用Servlet对象的init方法。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">2、在Servlet容器启动后：客户首次向Servlet发出请求，Servlet容器会判断内存中是否存在指定的Servlet对象，如果没有则创建它，然后根据客户的请求创建HttpRequest、&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpResponse对象，从而调用Servlet</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp; 对象的service方法。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">3、Servlet的类文件被更新后，重新创建Servlet</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Servlet容器在启动时自动创建Servlet，这是由在web.xml文件中为Servlet设置的&lt;load-on-startup&gt;属性决定</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 的。从中我们也能看到同一个类型的Servlet对象在Servlet容器中以单例的形式存在。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><strong>二、销毁Servlet对象的时机</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">1、<span style="color: #ff0000;">Servlet容器停止或者重新启动</span>：Servlet容器调用Servlet对象的destroy方法来释放资源。以上所讲的就是Servlet对象的生命周期。那么Servlet容器如何知道创建哪一个Servlet对象？</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">Servlet对象如何配置？实际上这些信息是通过读取web.xml配置文件来实现的。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">我们来看一下web.xml文件中的Servlet对象的配置节信息</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&lt;servlet&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;servlet-name&gt;action&lt;servlet-name&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;init-param&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-name&gt;config&lt;/param-name&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;/init-param&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;init-param&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-name&gt;detail&lt;/param-name&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-value&gt;2&lt;/param-value&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;/init-param&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;init-param&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-name&gt;debug&lt;/param-name&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-value&gt;2&lt;/param-value&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;/init-param&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&lt;/servlet&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&lt;servlet-mapping&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;servlet-name&gt;action&lt;/servlet-name&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; &lt;url-pattern&gt;*.do&lt;/url-pattern&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&lt;/servlet-mapping&gt;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">下面对上面的配置节信息进行解析</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">servlet-name：Servlet对象的名称</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">servlet-class：创建Servlet对象所要调用的类</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">param-name：参数名称</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">param-value：参数值</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">load-on-startup：Servlet容器启动时加载Servlet对象的顺序</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">servlet-mapping/servlet-name：要与servlet中的servlet-name配置节内容对应</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">url-pattern：客户访问的Servlet的相对URL路径</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当Servlet容器启动的时候读取&lt;servlet&gt;配置节信息，根据&lt;servlet-class&gt;配置节信息创建Servlet对象，同时根据&lt;init-param&gt;配置节信息创建HttpServletConfig对象，然后执行Servlet对象的init方法，并且根据&lt;load-on-startup&gt;配置节信息来决定创建Servlet对象的顺序，如果此配置节信息为负数或者没有配置，那么在Servlet容器启动时，将不加载此Servlet对象。当客户访问Servlet容器时，Servlet容器根据客户访问的URL地址，通过&lt;servlet-mapping&gt;配置节中的&lt;url-pattern&gt;配置节信息找到指定的Servlet对象，并调用此Servlet对象的service方法。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><a href="http://www.diybl.com/course/3_program/java/javajs/20081123/152271.html" style="color: #7d0000;"></a>&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">为了验证下，我新建了一个web app工程，新建一个Servlet，如下:</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;<embed wmode="transparent" src="http://sunnylocus.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=package%20com.tdt.servlet%3B%0A%0Aimport%20java.io.IOException%3B%0Aimport%20java.io.PrintWriter%3B%0Aimport%20javax.servlet.ServletException%3B%0Aimport%20javax.servlet.http.HttpServlet%3B%0Aimport%20javax.servlet.http.HttpServletRequest%3B%0Aimport%20javax.servlet.http.HttpServletResponse%3B%0A%0Apublic%20class%20TestServlet%20extends%20HttpServlet%20%7B%0A%09public%20void%20doGet(HttpServletRequest%20request%2C%20HttpServletResponse%20response)%0A%09%09%09throws%20ServletException%2C%20IOException%20%7B%0A%09%09this.doPost(request%2C%20response)%3B%0A%09%7D%0A%09public%20void%20doPost(HttpServletRequest%20request%2C%20HttpServletResponse%20response)%0A%09%09%09throws%20ServletException%2C%20IOException%20%7B%0A%0A%09%09response.setContentType(%22text%2Fhtml%22)%3B%0A%09%09PrintWriter%20out%20%3D%20response.getWriter()%3B%0A%09%09out.println(%22Hello%2Cthis%20is%20a%20test%22)%3B%0A%09%0A%09%09out.flush()%3B%0A%09%09out.close()%3B%0A%09%7D%0A%0A%09public%20void%20destroy()%20%7B%0A%09%09System.err.println(getServletName()%2B%22%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%BB%93%E6%9D%9F%22)%3B%3B%0A%09%7D%0A%09%0A%09public%20void%20init()%20throws%20ServletException%20%7B%0A%09%09System.out.println(getServletName()%2B%22%E6%89%A7%E8%A1%8C%E5%88%9D%E5%A7%8B%E5%8C%96%22)%3B%0A%09%7D%0A%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #7d0000;"><img src="http://sunnylocus.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">package</span>&nbsp;com.tdt.servlet;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;java.io.IOException;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;java.io.PrintWriter;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;javax.servlet.ServletException;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;javax.servlet.http.HttpServlet;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;javax.servlet.http.HttpServletRequest;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;javax.servlet.http.HttpServletResponse;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;TestServlet&nbsp;<span style="color: #7f0055;">extends</span>&nbsp;HttpServlet&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;doGet(HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">throws</span>&nbsp;ServletException,&nbsp;IOException&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">this</span>.doPost(request,&nbsp;response);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;doPost(HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">throws</span>&nbsp;ServletException,&nbsp;IOException&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.setContentType("text/html");&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrintWriter&nbsp;out&nbsp;=&nbsp;response.getWriter();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.println("Hello,this&nbsp;is&nbsp;a&nbsp;test");&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.flush();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.close();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;destroy()&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.err.println(getServletName()+"生命周期结束");;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;init()&nbsp;<span style="color: #7f0055;">throws</span>&nbsp;ServletException&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(getServletName()+"执行初始化");&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;当servlet被销毁时会在控制台上打印提示语句，不过我发现在tomcat中，只要不停止web容器，servlet是不会被销毁的。有没有什么方法，当service方法执行完毕就销毁这个servlet呢，我问了下老师，他说写一个监听器，不过我不知道怎么去实现它，如果有朋友知道实现的过程，还请赐教。</p><img src ="http://www.blogjava.net/brock/aggbug/396076.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-03-05 14:09 <a href="http://www.blogjava.net/brock/archive/2013/03/05/396076.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【Spring】IOC核心源码学习（二）：容器初始化过程</title><link>http://www.blogjava.net/brock/archive/2013/02/28/395832.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Thu, 28 Feb 2013 03:04:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/02/28/395832.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/395832.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2013/02/28/395832.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/395832.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/395832.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: http://singleant.iteye.com/blog/1177358&nbsp;接上文&nbsp;啃啃老菜： Spring IOC核心源码学习（一）&nbsp;，本文将以&nbsp;ClassPathXmlApplicationContext&nbsp;这个容器的实现作为基础，学习容器的初始化过程。ClassPathXmlApplicationContext&nbsp;类体系结构以下是&...&nbsp;&nbsp;<a href='http://www.blogjava.net/brock/archive/2013/02/28/395832.html'>阅读全文</a><img src ="http://www.blogjava.net/brock/aggbug/395832.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-02-28 11:04 <a href="http://www.blogjava.net/brock/archive/2013/02/28/395832.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring IOC核心源码学习（一）</title><link>http://www.blogjava.net/brock/archive/2013/02/28/395830.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Thu, 28 Feb 2013 02:46:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/02/28/395830.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/395830.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2013/02/28/395830.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/395830.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/395830.html</trackback:ping><description><![CDATA[<p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">本文主要以<span style="font-size: 11pt; font-family: 'Courier New';">spring ioc</span>容器基本代码骨架为切入点，理解<span style="font-size: 11pt; font-family: 'Courier New';">ioc</span>容器的基本代码组件结构，各代码组件细节剖析将放在后面的学习文章里。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;<span style="font-family: verdana, 'courier new'; line-height: 21px;">http://www.iteye.com/topic/1113459</span></p><h1><span style="font-size: 11pt; font-family: 'Courier New';"><span style="font-size: large;">关于IOC容器</span></span></h1><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">IoC</span>容器：最主要是完成了完成对象的创建和依赖的管理注入等等。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><strong>先从我们自己设计这样一个视角来考虑：</strong><strong></strong></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">所谓控制反转，就是把原先我们代码里面需要实现的对象创建、依赖的代码，反转给容器来帮忙实现。那么必然的我们需要创建一个容器，同时需要一种描述来让容器知道需要创建的对象与对象的关系。这个描述最具体表现就是我们可配置的文件。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><em>对象和对象关系怎么表示？</em><em></em></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><em>可以用</em><em><span style="font-size: 11pt; font-family: 'Courier New';">xml</span></em><em>，</em><em><span style="font-size: 11pt; font-family: 'Courier New';">properties</span></em><em>文件等语义化配置文件表示。</em><em></em></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><em>描述对象关系的文件存放在哪里？</em><em></em></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><em>可能是</em><em><span style="font-size: 11pt; font-family: 'Courier New';">classpath</span></em><em>，</em><em><span style="font-size: 11pt; font-family: 'Courier New';">filesystem</span></em><em>，或者是</em><em><span style="font-size: 11pt; font-family: 'Courier New';">URL</span></em><em>网络资源，</em><em><span style="font-size: 11pt; font-family: 'Courier New';">servletContext</span></em><em>等。</em><em></em></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">回到正题，有了配置文件，还需要对配置文件解析。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><em>不同的配置文件对对象的描述不一样，如标准的，自定义声明式的，如何统一？</em><em>&nbsp;</em><em>在内部需要有一个统一的关于对象的定义，所有外部的描述都必须转化成统一的描述定义。</em><em></em></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><em>如何对不同的配置文件进行解析？需要对不同的配置文件语法，采用不同的解析器。</em><em></em></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="color: #ff0000;"><strong>基于以上问题，对应过来，刚好是&nbsp;</strong><strong><span style="font-size: 11pt; font-family: 'Courier New';">spring ioc</span>&nbsp;</strong><strong>容器抽象的的几个主要接口：</strong></span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><strong></strong></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">Resource</span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">BeanDefinition</span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">BeanDefinitionReader</span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">BeanFactory</span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">ApplicationContext</span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">以上五个都是接口，都有各式各样的实现，正是这<span style="font-size: 11pt; font-family: 'Courier New'; color: red;">5</span>个接口定义了<span style="font-size: 11pt; font-family: 'Courier New'; color: red;">spring ioc</span>容器的基本代码组件结构。而其组件各种实现的组合关系组成了一个运行时的具体容器。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><h1><span style="font-size: 11pt; font-family: 'Courier New';"><strong><span style="font-size: large;">各代码组件详解</span></strong></span></h1><h1><strong><span style="font-size: 11pt; font-family: 'Courier New';">1.Resource</span></strong></h1><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">是对资源的抽象，每一个接口实现类都代表了一种资源类型，如<span style="font-size: 11pt; font-family: 'Courier New';">ClasspathResource</span>、<span style="font-size: 11pt; font-family: 'Courier New';">URLResource</span>，<span style="font-size: 11pt; font-family: 'Courier New';">FileSystemResource</span>等。每一个资源类型都封装了对某一种特定资源的访问策略。它是<span style="font-size: 11pt; font-family: 'Courier New';">spring</span>资源访问策略的一个基础实现，应用在很多场景。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;<br /><img alt="" src="http://dl.iteye.com/upload/attachment/536177/ead09fcb-3c6c-3740-9e36-6de33fd65cca.jpg" style="border: 0px;" /></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">具体可以参考文章<span style="font-size: 11pt; font-family: 'Courier New';">:</span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">Spring&nbsp;</span>资源访问剖析和策略模式应用</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';"><a href="http://www.ibm.com/developerworks/cn/java/j-lo-spring-resource/index.html" style="color: #006699;">http://www.ibm.com/developerworks/cn/java/j-lo-spring-resource/index.html</a></span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><strong><span style="font-size: 11pt; font-family: 'Courier New';">2.BeanDefinition</span></strong></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">用来抽象和描述一个具体<span style="font-size: 11pt; font-family: 'Courier New';">bean</span>对象。是描述一个<span style="font-size: 11pt; font-family: 'Courier New';">bean</span>对象的基本数据结构。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><strong><span style="font-size: 11pt; font-family: 'Courier New';">3.BeanDefinitionReader</span></strong></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">BeanDefinitionReader</span>将外部资源对象描述的<span style="font-size: 11pt; font-family: 'Courier New';">bean</span>定义统一转化为统一的内部数据结构<span style="font-size: 11pt; font-family: 'Courier New';">BeanDefinition</span>。对应不同的描述需要有不同的<span style="font-size: 11pt; font-family: 'Courier New';">Reader</span>。如<span style="font-size: 11pt; font-family: 'Courier New';">XmlBeanDefinitionReader</span>用来读取<span style="font-size: 11pt; font-family: 'Courier New';">xml</span>描述配置的<span style="font-size: 11pt; font-family: 'Courier New';">bean</span>对象。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';"><br /><img alt="" src="http://dl.iteye.com/upload/attachment/536179/c4143d16-02e2-3d7b-9734-4d19a9a984dd.jpg" style="border: 0px;" /><br />&nbsp;</span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><strong><span style="font-size: 11pt; font-family: 'Courier New';">4.BeanFactory</span></strong></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">用来定义一个很纯粹的<span style="font-size: 11pt; font-family: 'Courier New';">bean</span>容器。它是一个<span style="font-size: 11pt; font-family: 'Courier New';">bean</span>容器的必备结构。同时和外部应用环境等隔离。<span style="font-size: 11pt; font-family: 'Courier New';">BeanDefinition</span>是它的基本数据结构。它维护一个<span style="font-size: 11pt; font-family: 'Courier New';">BeanDefinitions Map,</span>并可根据<span style="font-size: 11pt; font-family: 'Courier New';">BeanDefinition</span>的描述进行<span style="font-size: 11pt; font-family: 'Courier New';">bean</span>的创建和管理。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';"><br /><img alt="" src="http://dl.iteye.com/upload/attachment/536181/24095923-75cd-363b-bc2f-9fbc603c341f.jpg" style="border: 0px;" /><br />&nbsp;</span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><strong><span style="font-size: 11pt; font-family: 'Courier New';">5.ApplicationContext</span></strong></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">从名字来看叫应用上下文，是和应用环境息息相关的。没错这个就是我们平时开发中经常直接使用打交道的一个类，应用上下文，或者也叫做<span style="font-size: 11pt; font-family: 'Courier New';">spring</span>容器。其实它的基本实现是会持有一个<span style="font-size: 11pt; font-family: 'Courier New';">BeanFactory</span>对象，并基于此提供一些包装和功能扩展。为什么要这么做呢？因为<span style="font-size: 11pt; font-family: 'Courier New';">BeanFactory</span>实现了一个容器基本结构和功能，但是与外部环境隔离。那么读取配置文件，并将配置文件解析成<span style="font-size: 11pt; font-family: 'Courier New';">BeanDefinition</span>，然后注册到<span style="font-size: 11pt; font-family: 'Courier New';">BeanFactory</span>的这一个过程的封装自然就需要<span style="font-size: 11pt; font-family: 'Courier New';">ApplicationContext</span>。<span style="font-size: 11pt; font-family: 'Courier New';">ApplicationContext</span>和应用环境细细相关，常见实现有<span style="font-size: 11pt; font-family: 'Courier New';">ClasspathXmlApplicationContext,FileSystemXmlApplicationContext,WebApplicationContext</span>等。<span style="font-size: 11pt; font-family: 'Courier New';">Classpath</span>、<span style="font-size: 11pt; font-family: 'Courier New';">xml</span>、<span style="font-size: 11pt; font-family: 'Courier New';">FileSystem</span>、<span style="font-size: 11pt; font-family: 'Courier New';">Web</span>等词都代表了应用和环境相关的一些意思，从字面上不难理解各自代表的含义。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">当然<span style="font-size: 11pt; font-family: 'Courier New';">ApplicationContext</span>和<span style="font-size: 11pt; font-family: 'Courier New';">BeanFactory</span>的区别远不止于此，有：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">1.<span style="font-family: 'Times New Roman';">&nbsp;&nbsp;</span></span>资源访问功能：在<span style="font-size: 11pt; font-family: 'Courier New';">Resource</span>和<span style="font-size: 11pt; font-family: 'Courier New';">ResourceLoader</span>的基础上可以灵活的访问不同的资源。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">2.<span style="font-family: 'Times New Roman';">&nbsp;&nbsp;</span></span>支持不同的信息源。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">3.<span style="font-family: 'Times New Roman';">&nbsp;&nbsp;</span></span>支持应用事件：继承了接口<span style="font-size: 11pt; font-family: 'Courier New';">ApplicationEventPublisher</span>，这样在上下文中为<span style="font-size: 11pt; font-family: 'Courier New';">bean</span>之间提供了事件机制。</p><p style="margin: 0cm 0cm 0pt 18pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">&#8230;&#8230;</span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';"><br /><img alt="" src="http://dl.iteye.com/upload/attachment/536183/c456f949-7b9c-34db-ad1a-ca3141219b6d.jpg" style="border: 0px;" /><br />&nbsp;</span></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">以上<span style="font-size: 11pt; font-family: 'Courier New';">5</span>个组件基本代表了<span style="font-size: 11pt; font-family: 'Courier New';">ioc</span>容器的一个最基本组成，而组件的组合是放在<span style="font-size: 11pt; font-family: 'Courier New';">ApplicationContext</span>的实现这一层来完成。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><strong><span style="color: #ff0000;">以ClasspathXmlApplicationContext 容器实现为例，其组合关系如下：</span></strong></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><br /><img alt="" src="http://dl.iteye.com/upload/attachment/536932/ae2612a4-5840-3b00-a585-037a5a4980ac.jpg" style="border: 0px;" /></p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">ClassPathXmlApplicationContext的refresh() 方法负责完成了整个容器的初始化。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">为什么叫refresh？也就是说其实是刷新的意思，该IOC容器里面维护了一个单例的BeanFactory，如果bean的配置有修改，也可以直接调用refresh方法，它将销毁之前的BeanFactory，重新创建一个BeanFactory。所以叫refresh也是能理解的。</p><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">以下是Refresh的基本步骤：<br /><strong>1.把配置xml文件转换成resource。resource的转换是先通过ResourcePatternResolver来解析可识别格式的配置文件的路径<br />(如"classpath*:"等)，如果没有指定格式，默认会按照类路径的资源来处理。&nbsp;<br />2.利用XmlBeanDefinitionReader完成对xml的解析，将xml Resource里定义的bean对象转换成统一的BeanDefinition。<br />3.将BeanDefinition注册到BeanFactory，完成对BeanFactory的初始化。BeanFactory里将会维护一个BeanDefinition的Map。<br /></strong><br />当getBean的时候就会根据调用BeanFactory，根据bean的BeanDifinition来实例化一个bean。当然根据bean的lazy-init、protetype等属性设置不同以上过程略有差别。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">refresh()代码如下：</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.2847290039063px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.19097328186035px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;<embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=%09public%20void%20refresh()%20throws%20BeansException%2C%20IllegalStateException%20%7B%0A%09%09synchronized%20(this.startupShutdownMonitor)%20%7B%0A%09%09%09%2F%2F%20Prepare%20this%20context%20for%20refreshing.%0A%09%09%09prepareRefresh()%3B%0A%0A%09%09%09%2F%2F%20Tell%20the%20subclass%20to%20refresh%20the%20internal%20bean%20factory.%0A%09%09%09ConfigurableListableBeanFactory%20beanFactory%20%3D%20obtainFreshBeanFactory()%3B%0A%0A%09%09%09%2F%2F%20Prepare%20the%20bean%20factory%20for%20use%20in%20this%20context.%0A%09%09%09prepareBeanFactory(beanFactory)%3B%0A%0A%09%09%09try%20%7B%0A%09%09%09%09%2F%2F%20Allows%20post-processing%20of%20the%20bean%20factory%20in%20context%20subclasses.%0A%09%09%09%09postProcessBeanFactory(beanFactory)%3B%0A%0A%09%09%09%09%2F%2F%20Invoke%20factory%20processors%20registered%20as%20beans%20in%20the%20context.%0A%09%09%09%09invokeBeanFactoryPostProcessors(beanFactory)%3B%0A%0A%09%09%09%09%2F%2F%20Register%20bean%20processors%20that%20intercept%20bean%20creation.%0A%09%09%09%09registerBeanPostProcessors(beanFactory)%3B%0A%0A%09%09%09%09%2F%2F%20Initialize%20message%20source%20for%20this%20context.%0A%09%09%09%09initMessageSource()%3B%0A%0A%09%09%09%09%2F%2F%20Initialize%20event%20multicaster%20for%20this%20context.%0A%09%09%09%09initApplicationEventMulticaster()%3B%0A%0A%09%09%09%09%2F%2F%20Initialize%20other%20special%20beans%20in%20specific%20context%20subclasses.%0A%09%09%09%09onRefresh()%3B%0A%0A%09%09%09%09%2F%2F%20Check%20for%20listener%20beans%20and%20register%20them.%0A%09%09%09%09registerListeners()%3B%0A%0A%09%09%09%09%2F%2F%20Instantiate%20all%20remaining%20(non-lazy-init)%20singletons.%0A%09%09%09%09finishBeanFactoryInitialization(beanFactory)%3B%0A%0A%09%09%09%09%2F%2F%20Last%20step%3A%20publish%20corresponding%20event.%0A%09%09%09%09finishRefresh()%3B%0A%09%09%09%7D%0A%0A%09%09%09catch%20(BeansException%20ex)%20%7B%0A%09%09%09%09%2F%2F%20Destroy%20already%20created%20singletons%20to%20avoid%20dangling%20resources.%0A%09%09%09%09beanFactory.destroySingletons()%3B%0A%0A%09%09%09%09%2F%2F%20Reset%20'active'%20flag.%0A%09%09%09%09cancelRefresh(ex)%3B%0A%0A%09%09%09%09%2F%2F%20Propagate%20exception%20to%20caller.%0A%09%09%09%09throw%20ex%3B%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;refresh()&nbsp;<span style="color: #7f0055;">throws</span>&nbsp;BeansException,&nbsp;IllegalStateException&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">synchronized</span>&nbsp;(<span style="color: #7f0055;">this</span>.startupShutdownMonitor)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Prepare&nbsp;this&nbsp;context&nbsp;for&nbsp;refreshing.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prepareRefresh();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Tell&nbsp;the&nbsp;subclass&nbsp;to&nbsp;refresh&nbsp;the&nbsp;internal&nbsp;bean&nbsp;factory.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ConfigurableListableBeanFactory&nbsp;beanFactory&nbsp;=&nbsp;obtainFreshBeanFactory();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Prepare&nbsp;the&nbsp;bean&nbsp;factory&nbsp;for&nbsp;use&nbsp;in&nbsp;this&nbsp;context.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prepareBeanFactory(beanFactory);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">try</span>&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Allows&nbsp;post-processing&nbsp;of&nbsp;the&nbsp;bean&nbsp;factory&nbsp;in&nbsp;context&nbsp;subclasses.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;postProcessBeanFactory(beanFactory);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Invoke&nbsp;factory&nbsp;processors&nbsp;registered&nbsp;as&nbsp;beans&nbsp;in&nbsp;the&nbsp;context.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;invokeBeanFactoryPostProcessors(beanFactory);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Register&nbsp;bean&nbsp;processors&nbsp;that&nbsp;intercept&nbsp;bean&nbsp;creation.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;registerBeanPostProcessors(beanFactory);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Initialize&nbsp;message&nbsp;source&nbsp;for&nbsp;this&nbsp;context.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initMessageSource();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Initialize&nbsp;event&nbsp;multicaster&nbsp;for&nbsp;this&nbsp;context.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initApplicationEventMulticaster();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Initialize&nbsp;other&nbsp;special&nbsp;beans&nbsp;in&nbsp;specific&nbsp;context&nbsp;subclasses.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onRefresh();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Check&nbsp;for&nbsp;listener&nbsp;beans&nbsp;and&nbsp;register&nbsp;them.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;registerListeners();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Instantiate&nbsp;all&nbsp;remaining&nbsp;(non-lazy-init)&nbsp;singletons.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finishBeanFactoryInitialization(beanFactory);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Last&nbsp;step:&nbsp;publish&nbsp;corresponding&nbsp;event.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finishRefresh();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">catch</span>&nbsp;(BeansException&nbsp;ex)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Destroy&nbsp;already&nbsp;created&nbsp;singletons&nbsp;to&nbsp;avoid&nbsp;dangling&nbsp;resources.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;beanFactory.destroySingletons();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Reset&nbsp;'active'&nbsp;flag.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cancelRefresh(ex);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Propagate&nbsp;exception&nbsp;to&nbsp;caller.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">throw</span>&nbsp;ex;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;以上的obtainFreshBeanFactory是很关键的一个方法，里面会调用loadBeanDefinition方法，如下：</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.2847290039063px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.19097328186035px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;<embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=%09protected%20void%20loadBeanDefinitions(DefaultListableBeanFactory%20beanFactory)%20throws%20IOException%20%7B%0A%09%09%2F%2F%20Create%20a%20new%20XmlBeanDefinitionReader%20for%20the%20given%20BeanFactory.%0A%09%09XmlBeanDefinitionReader%20beanDefinitionReader%20%3D%20new%20XmlBeanDefinitionReader(beanFactory)%3B%0A%0A%09%09%2F%2F%20Configure%20the%20bean%20definition%20reader%20with%20this%20context's%0A%09%09%2F%2F%20resource%20loading%20environment.%0A%09%09beanDefinitionReader.setResourceLoader(this)%3B%0A%09%09beanDefinitionReader.setEntityResolver(new%20ResourceEntityResolver(this))%3B%0A%0A%09%09%2F%2F%20Allow%20a%20subclass%20to%20provide%20custom%20initialization%20of%20the%20reader%2C%0A%09%09%2F%2F%20then%20proceed%20with%20actually%20loading%20the%20bean%20definitions.%0A%09%09initBeanDefinitionReader(beanDefinitionReader)%3B%0A%09%09loadBeanDefinitions(beanDefinitionReader)%3B%0A%09%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">protected</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;loadBeanDefinitions(DefaultListableBeanFactory&nbsp;beanFactory)&nbsp;<span style="color: #7f0055;">throws</span>&nbsp;IOException&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Create&nbsp;a&nbsp;new&nbsp;XmlBeanDefinitionReader&nbsp;for&nbsp;the&nbsp;given&nbsp;BeanFactory.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;XmlBeanDefinitionReader&nbsp;beanDefinitionReader&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;XmlBeanDefinitionReader(beanFactory);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Configure&nbsp;the&nbsp;bean&nbsp;definition&nbsp;reader&nbsp;with&nbsp;this&nbsp;context's</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;resource&nbsp;loading&nbsp;environment.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;beanDefinitionReader.setResourceLoader(<span style="color: #7f0055;">this</span>);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;beanDefinitionReader.setEntityResolver(<span style="color: #7f0055;">new</span>&nbsp;ResourceEntityResolver(<span style="color: #7f0055;">this</span>));&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;Allow&nbsp;a&nbsp;subclass&nbsp;to&nbsp;provide&nbsp;custom&nbsp;initialization&nbsp;of&nbsp;the&nbsp;reader,</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;then&nbsp;proceed&nbsp;with&nbsp;actually&nbsp;loading&nbsp;the&nbsp;bean&nbsp;definitions.</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;initBeanDefinitionReader(beanDefinitionReader);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;loadBeanDefinitions(beanDefinitionReader);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;LoadBeanDifinition方法很关键，这里特定于整个IOC容器，实例化了一个XmlBeanDefinitionReader来解析Resource文件。关于Resource文件如何初始化和xml文件如何解析都在</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.2847290039063px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.19097328186035px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;<embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=loadBeanDefinitions(beanDefinitionReader)%3B" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">loadBeanDefinitions(beanDefinitionReader);&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;">&nbsp;里面的层层调用完成，这里不在累述。</p><h1>小结&nbsp;</h1><p style=" padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">Spring</span>的扩展性是毋庸置疑的，学习<span style="font-size: 11pt; font-family: 'Courier New';">spring</span>的设计是一个很好的实践理论结合。主要个人觉得有几点：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">1.<span style="font-family: 'Times New Roman';">&nbsp;&nbsp;</span></span>框架顶层的设计有着很好的抽象，遵循面向接口编程的规范。<span style="font-size: 11pt; font-family: 'Courier New';">Resource</span>、<span style="font-size: 11pt; font-family: 'Courier New';">BeanFactory</span>、<span style="font-size: 11pt; font-family: 'Courier New';">ApplicationContext</span>都是非常好的接口抽象，非常明确的定义了该组件的一些功能。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">2.<span style="font-family: 'Times New Roman';">&nbsp;&nbsp;</span></span>利用组合模式。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">3.<span style="font-family: 'Times New Roman';">&nbsp;&nbsp;</span></span>个组件的实现里大量使用了模板方法模式，提升了同一组件代码的复用性。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">4.<span style="font-family: 'Times New Roman';">&nbsp;&nbsp;</span></span>各种设计保留了扩展的接口，很多基于<span style="font-size: 11pt; font-family: 'Courier New';">spring</span>的框架都可以很容易的介入实现了自己的一些扩展。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 25.19097328186035px; background-color: #efefef;"><span style="font-size: 11pt; font-family: 'Courier New';">5.<span style="font-family: 'Times New Roman';">&nbsp;&nbsp;</span></span>框架里采用里很多经典的设计模式，如代理、装饰、策略等等。<br /><br /></p><img src ="http://www.blogjava.net/brock/aggbug/395830.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-02-28 10:46 <a href="http://www.blogjava.net/brock/archive/2013/02/28/395830.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jvm 调优</title><link>http://www.blogjava.net/brock/archive/2013/02/27/395796.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Wed, 27 Feb 2013 06:25:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/02/27/395796.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/395796.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2013/02/27/395796.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/395796.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/395796.html</trackback:ping><description><![CDATA[<p><span style="font-family:宋体;">先来看下一X</span><span style="font-family: 宋体;">宝</span><span style="font-family:宋体;">经典配置：</span></p>  <p>&nbsp;</p>  <p>/opt/taobao/java/bin/java -Dprogram.name=run.sh &#8211;server</p>  <p>&nbsp;-Xms4g&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //<span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">指定</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;"> jvm </span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">的最小</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;"> heap </span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">大小&nbsp;</span><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: x-small; line-height: 25.2px; background-color: #ffffff;">（-Xms默认是物理内存的1/4)</span></p>  <p>&nbsp;-Xmx4g&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //<span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">指定</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;"> jvm </span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">的最大</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;"> heap </span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">大小</span></p>  <p>&nbsp;-Xmn2g</p>  <p>&nbsp;-Xss1m</p>  <p>&nbsp;-XX:PermSize=96m</p>  <p>&nbsp;-XX:MaxPermSize=256m</p>  <p>&nbsp;-XX:SurvivorRatio=10</p>  <p>&nbsp;-XX:+HeapDumpOnOutOfMemoryError&nbsp;&nbsp;&nbsp; //</p>  <p>&nbsp;-XX:HeapDumpPath=/home/admin/logs/java.hprof -verbose:gc -Xloggc:/home/admin/logs/gc.log</p>  <p>&nbsp;-XX:+PrintGCDetails</p>  <p>&nbsp;-XX:+PrintGCDateStamps</p>  <p>&nbsp;-XX:+UseConcMarkSweepGC</p>  <p>&nbsp;-XX:+UseCMSCompactAtFullCollection</p>  <p>&nbsp;-XX:CMSInitiatingOccupancyFraction=80</p>  <p>&nbsp;-XX:+UseCompressedOops</p>  <p>&nbsp;-XX:+DisableExplicitGC</p>  <p>&nbsp;-Djava.awt.headless=true</p>  <p>&nbsp;-Dsun.net.client.defaultConnectTimeout=10000</p>  <p>&nbsp;-Dsun.net.client.defaultReadTimeout=30000</p>  <p>&nbsp;-Djava.net.preferIPv4Stack=true</p>  <p>&nbsp;-Djava.endorsed.dirs=/opt/taobao/jboss/lib/endorsed</p>  <p>&nbsp;-classpath /opt/taobao/jboss/bin/run.jar:/opt/taobao/java/lib/tools.jar org.jboss.Main -b 0.0.0.0 -Djboss.server.home.dir=/home/admin/purdecision/.default -Djboss.server.home.url=file:/home/admin/purdecision/.default</p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">这二年来这一堆东西我从来没有怀疑过，&#8220;绝对正确完美&#8221;，据说是X宝的标配。以至于从来没有去分析了解过（一知半解），可能真的是惰性使然，也可能&#8220;忙&#8221;吧。无意中看到有人在博客里写到</span> <span style="font-family:宋体;">&#8220;温故知新&#8221;，就像有人说读</span>think in java<span style="font-family:宋体;">一样每一回都有新的发现。下面就分析一下为什么要设置这些参数，有何意义。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">上面参数说明：</span></p>  <p><strong>-Xmx4g :</strong></p>  <p>&nbsp;<span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">指定</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;"> jvm </span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">的最大</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;"> heap </span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">大小，默认值为物理内存的</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">1/4</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">，最佳设值应该视物理内存大小及计算机内其他内存开销而定</span></p>  <p>&nbsp;</p>  <p><strong>-Xms4g :</strong></p>  <p>&nbsp;<span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">指定</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;"> jvm </span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">的最小</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;"> heap </span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">大小。些值设置与</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">-Xmx</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">相同，以避免每次垃圾回收完成后</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">JVM</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">重新分配内存</span></p>  <p>&nbsp;</p>  <p><strong>-Xmn2g : </strong></p>  <p><span style="font-family:宋体;">设置年轻代大小为</span>2G<span style="font-family:宋体;">。整个堆大小</span>=<span style="font-family:宋体;">年轻代大小</span> + <span style="font-family:宋体;">年老代大小</span> + <span style="font-family:宋体;">持久代大小。持久代一般</span></p>  <p><span style="font-family:宋体;">固定大小为</span>64m<span style="font-family:宋体;">，所以增大年轻代后，将会减小年老代大小。<span style="color:red">此值对系统性能影响较大，</span></span><span style="color:red">Sun</span><span style="font-family:宋体;color:red">官方推</span></p>  <p><span style="font-family:宋体; color:red">荐配置为整个堆的</span><span style="color:red">3/8</span><span style="font-family:宋体;">。</span>(<span style="font-family:宋体;">按此说应设置为</span>1.5G)</p>  <p><strong>-Xss1m</strong></p>  <p><span style="font-family:宋体;">每个线程堆栈大小为</span>1M. <span style="font-family:宋体;">根据应用的线程所需内存大小进行调整。在相同物理内存下</span>,<span style="font-family:宋体;">减小这个值能生成更多的线程。（本机由于</span>forest<span style="font-family:宋体;">的原因</span>-Xss2m<span style="font-family:宋体;">，原因</span>1<span style="font-family:宋体;">：物理内存过小</span> 2<span style="font-family:宋体;">：</span>window<span style="font-family:宋体;">线程不能太多</span> <span style="font-family:宋体;">猜的）</span></p>  <p>&nbsp;</p>  <p><strong>-XX:PermSize=96m</strong></p>  <p><span style="font-family:宋体; color:#454545;background:white">用于存放静态文件，如今</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:#454545; background:white">Java</span><span style="font-family: 宋体; color:#454545;background:white">类、方法等。持久代对垃圾回收没有显著影响，但是有些应用可能动态生成或</span></p>  <p><span style="font-family:宋体; color:#454545;background:white">者调用一些</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:#454545;background:white">class</span><span style="font-family:宋体;color:#454545;background:white">，例如</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;; color:#454545;background:white">Hibernate</span><span style="font-family:宋体;color:#454545;background:white">等，在这种时候需要设置一个比较大的持久代空间来存放这些运行过程中新</span></p>  <p><span style="font-family:宋体; color:#454545;background:white">增的类。持久代大小通过</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:#454545; background:white">-XX:MaxPermSize=&lt;N&gt;</span><span style="font-family:宋体;color:#454545;background:white">进行设置</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;; color:#454545"><br /> <br /> <span style="background:white">-XX:PermSize=64MB </span></span><span style="font-family:宋体;color:#454545;background:white">最小尺寸，初始分配</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;; color:#454545"><br /> <span style="background:white">-XX:MaxPermSize=256MB </span></span><span style="font-family:宋体;color:#454545;background:white">最大允许分配尺寸，按需分配</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;; color:#454545"><br /> </span><span style="font-family:宋体;color:#454545; background:white">过小会导致：</span><span style=" font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:#454545;background:white">java.lang.OutOfMemoryError: PermGen space</span><span style=" font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:#454545"><br /> <br /> <span style="background:white">MaxPermSize</span></span><span style="font-family:宋体;color:#454545;background:white">缺省值和</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;; color:#454545;background:white">-server -client</span><span style="font-family:宋体;color:#454545;background:white">选项相关。</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;; color:#454545"><br /> <span style="background:white">-server</span></span><span style="font-family:宋体;color:#454545;background:white">选项下默认</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;; color:#454545;background:white">MaxPermSize</span><span style="font-family:宋体;color:#454545;background:white">为</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;; color:#454545;background:white">64m</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:#454545"><br /> <span style="background:white">-client</span></span><span style="font-family:宋体;color:#454545;background:white">选项下默认</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;; color:#454545;background:white">MaxPermSize</span><span style="font-family:宋体;color:#454545;background:white">为</span><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;; color:#454545;background:white">32m</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">（为什么不是</span>64M <span style="font-family:宋体;">可能是</span>webx<span style="font-family:宋体;">设置的持久代空间比较多）</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p><strong>-XX:SurvivorRatio=10</strong></p>  <p><span style="font-family:宋体;">（</span>SurvivorRatio=4<span style="font-family:宋体;">设置年轻代中</span>Eden<span style="font-family:宋体;">区与</span>Survivor<span style="font-family:宋体;">区的大小比值。设置为</span>4<span style="font-family:宋体;">，则两个</span>Survivor</p>  <p><span style="font-family:宋体;">区与一个</span>Eden<span style="font-family:宋体;">区的比值为</span>2:4<span style="font-family:宋体;">，一个</span>Survivor<span style="font-family:宋体;">区占整个年轻代的</span>1/6<span style="font-family:宋体;">）</span></p>  <p><span style="font-family:宋体;">这里设置为</span>10<span style="font-family:宋体;">也就是说一个</span>Survivor<span style="font-family:宋体;">区占整个年轻代的</span>1/12<span style="font-family:宋体;">，这个参数是否能小一点，毕竟我们的应用中没有创建很大的对像。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">这个值设了有什么用？</span></p>  <p><span style="font-family:宋体;">上面配置中</span>-Xmn2g <span style="font-family:宋体;">年轻代大小，</span>SurvivorRatio<span style="font-family:宋体;">为</span>10<span style="font-family:宋体;">时</span> <span style="font-family:宋体;">：</span>Eden<span style="font-family:宋体;">超过</span>1.66G<span style="font-family:宋体;">时触发</span>minor gc(young generation)</p>  <p><span style="font-family:宋体;">我的应用</span>gc <span style="font-family:宋体;">日志一直在</span>young gc <span style="font-family:宋体;">就是如此，看来我的应用</span> eden<span style="font-family:宋体;">区还是设的很大的。</span> </p>  <p>&nbsp;</p>  <p><strong><span style="font-family: Helvetica, sans-serif;"><br /> <span style="background:white">&nbsp;-XX:+HeapDumpOnOutOfMemoryError</span></span></strong></p>  <p><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">参数表示当</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">JVM</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">发生</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">OOM</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">时，自动生成</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">DUMP</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">文件。</span>&nbsp;</p>  <p>&nbsp;</p>  <p><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">-XX:HeapDumpPath=${</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">目录</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">}</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">参数表示生成</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">DUMP</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">文件的路径，也可以指定文件名称，例如：</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">-XX:HeapDumpPath=${</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">目录</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">}/java_heapdump.hprof</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">。如果不指定文件名，默认为：</span><span style="font-family: Helvetica, sans-serif; background-color: white; background-position: initial initial; background-repeat: initial initial;">java_&lt;pid&gt;_&lt;date&gt;_&lt;time&gt;_heapDump.hprof</span><span style="font-family: 宋体; background-color: white; background-position: initial initial; background-repeat: initial initial;">。</span></p>  <p>&nbsp;</p>  <p><strong>-XX:+PrintGCDetails</strong><strong><span style="font-family:宋体;">：</span></strong></p>  <p><span style="font-family:宋体;">输出形式：</span>[GC [DefNew: 8614K-&gt;781K(9088K), 0.0123035 secs] 118250K-&gt;113543K(130112K), 0.0124633 secs] [GC [DefNew: 8614K-&gt;8614K(9088K), 0.0000665 secs][Tenured:</p>  <p>112761K-&gt;10414K(121024K), 0.0433488 secs] 121376K-&gt;10414K(130112K), 0.0436268 secs]</p>  <p>&nbsp;</p>  <p>-XX:+PrintGCTimeStamps -XX:+PrintGC<span style="font-family:宋体;">：</span>PrintGCTimeStamps<span style="font-family:宋体;">可与上面两个混合使用</span></p>  <p><span style="font-family:宋体;">输出形式：</span>11.851: [GC 98328K-&gt;93620K(130112K), 0.0082960 secs]</p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p><strong>-XX:+UseConcMarkSweepGC </strong>&nbsp;</p>  <p><span style="font-family:宋体;">设置并发收集器</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">可以保证大部分工作都并发进行（应用不停止），垃圾回收只暂停很少的时间，此收集器适合对响应时间要求</span></p>  <p><span style="font-family:宋体;">比较高的中、大规模应用。使用</span>-XX:+UseConcMarkSweepGC<span style="font-family:宋体;">打开。</span></p>  <p><span style="font-family:宋体;">并发收集器主要减少年老代的暂停时间，他在应用不停止的情况下使用独立的垃圾回收线程，跟踪可达对</span></p>  <p><span style="font-family:宋体;">象。在每个年老代垃圾回收周期中，在收集初期并发收集器</span> <span style="font-family:宋体;">会对整个应用进行简短的暂停，在收集中还会再暂</span></p>  <p><span style="font-family:宋体;">停一次。第二次暂停会比第一次稍长，在此过程中多个线程同时进行垃圾回收工作。</span></p>  <p>&nbsp;</p>  <p><span style="color:red">CMS</span><span style="font-family:宋体;color:red">采用的基础算法是：标记&#8212;清除</span> <span style="font-family:宋体; color:red">所有</span><span style="color:red">CMS</span><span style="font-family:宋体;color:red">不会整理、压缩堆空间。这样就会有一个问题：经过</span><span style="color:red">CMS</span><span style="font-family:宋体; color:red">收集的堆会产生空间碎片</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p><strong>-XX:CMSInitiatingOccupancyFraction=80</strong></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">启动并发收集器：因为并发收集在应用运行时进行收集，所以必须保证收集完成之前有足够的内存空间供程</span></p>  <p><span style="font-family:宋体;">序使用，否则会出现&#8220;</span>Concurrent Mode Failure<span style="font-family:宋体;">&#8221;。通过设置</span>-XX:CMSInitiatingOccupancyFraction=&lt;N&gt;</p>  <p><span style="font-family:宋体;">指定还有多少剩余堆时开始执行并发收集</span></p>  <p>&nbsp;</p>  <p>-<strong>XX:+UseCMSCompactAtFullCollection</strong><strong><span style="font-family:宋体;">：</span></strong></p>  <p><span style="font-family:宋体;">打开对年老代的压缩。可能会影响性能，但是可以消除碎片</span></p>  <p>&nbsp;</p>  <p><strong>XX:+UseCompressedOops</strong></p>  <p><span style="font-size: 11pt; font-family: 宋体;">通常</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;">64</span><span style="font-size: 11pt; font-family: 宋体;">位</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;">JVM</span><span style="font-size: 11pt; font-family: 宋体;">消耗的内存会比</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;">32</span><span style="font-size: 11pt; font-family: 宋体;">位的大</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;">1.5</span><span style="font-size: 11pt; font-family: 宋体;">倍，这是因为对象指针在</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;">64</span><span style="font-size: 11pt; font-family: 宋体;">位架构下，长度会翻倍（更宽的寻址）。</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;"><br /> </span><span style="font-size: 11pt; font-family: 宋体;">对于那些将要从</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;">32</span><span style="font-size: 11pt; font-family: 宋体;">位平台移植到</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;">64</span><span style="font-size: 11pt; font-family: 宋体;">位的应用来说，平白无辜多了</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;">1/2</span><span style="font-size: 11pt; font-family: 宋体;">的内存占用，这是开发者不愿意看到的。</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;"><br /> </span><span style="font-size: 11pt; font-family: 宋体;">幸运的是，从</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;">JDK 1.6 update14</span><span style="font-size: 11pt; font-family: 宋体;">开始，</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;">64 bit JVM</span><span style="font-size: 11pt; font-family: 宋体;">正式支持了</span><span style="font-size: 11pt; font-family: Helvetica, sans-serif;"> -XX:+UseCompressedOops </span><span style="font-size: 11pt; font-family: 宋体;">这个可以压缩指针，起到节约内存占用的新参数</span></p>  <p>&nbsp;</p>  <p><strong>-XX:-DisableExplicitGC </strong></p>  <p><span style="font-family:宋体;">将会忽略手动调用</span>GC<span style="font-family:宋体;">的代码，如：</span>System.gc()<span style="font-family:宋体;">，将</span>-DisableExplicitGC<span style="font-family:宋体;">，</span> <span style="font-family:宋体;">改成</span>+DisableExplicitGC<span style="font-family:宋体;">即为启用，默认为启用，什么也不写，默认是加号，但是系统内部默认的并不是什么都启用</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">至此为什么</span>Xmx<span style="font-family:宋体;">与</span>xms <span style="font-family:宋体;">一样，为什么用</span><span style="color:red">CMS</span><span style="font-family:宋体;">（并发收集器），为什么用了</span>cms <span style="font-family:宋体;">要使用</span>-XX:+UseCMSCompactAtFullCollection<span style="font-family: 宋体;">，为什么用</span>XX:+UseCompressedOops<span style="font-family:宋体;">等等，相信大家和我一样有所了解。不过对于有些还是不清楚理解有误，可能还要来来回回捣腾，不足之处请大家补充。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p><img src ="http://www.blogjava.net/brock/aggbug/395796.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-02-27 14:25 <a href="http://www.blogjava.net/brock/archive/2013/02/27/395796.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java 静态代理和动态代理</title><link>http://www.blogjava.net/brock/archive/2013/02/21/395513.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Thu, 21 Feb 2013 04:01:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/02/21/395513.html</guid><description><![CDATA[<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">1. 代理模式主要有两种：静态代理和动态代理&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">2. 静态代理：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">比如要在输出&#8220;HelloWorld&#8221;前打印一个字符串&#8220;Welcome&#8221;&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">A:先定义一个接口类&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;<embed wmode="transparent" src="http://kuangbaoxu.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=package%20ttitfly.proxy%3B%20%20%20%20%0A%20%20%20%0Apublic%20interface%20HelloWorld%20%7B%20%20%20%20%0A%20%20%20%20public%20void%20print()%3B%20%20%20%20%0A%2F%2F%20%20public%20void%20say()%3B%20%20%20%20%0A%7D%20" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://kuangbaoxu.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">package</span>&nbsp;ttitfly.proxy;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">interface</span>&nbsp;HelloWorld&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;print();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//&nbsp;&nbsp;public&nbsp;void&nbsp;say();&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;&nbsp;</li></ol></div><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">B: 定义一个该接口的实现类&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">java 代码&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;<embed wmode="transparent" src="http://kuangbaoxu.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=package%20ttitfly.proxy%3B%20%20%20%20%0A%20%20%20%0Apublic%20class%20HelloWorldImpl%20implements%20HelloWorld%7B%20%20%20%20%0A%20%20%20%0A%20%20%20%20public%20void%20print()%7B%20%20%20%20%0A%20%20%20%20%20%20%20%20System.out.println(%22HelloWorld%22)%3B%20%20%20%20%0A%20%20%20%20%7D%20%20%20%20%0A%2F%2F%20%20public%20void%20say()%7B%20%20%20%20%0A%2F%2F%20%20%20%20%20%20System.out.println(%22Say%20Hello!%22)%3B%20%20%20%20%0A%2F%2F%20%20%7D%20%20%20%20%0A%7D%20%20%20%20" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://kuangbaoxu.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">package</span>&nbsp;ttitfly.proxy;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;HelloWorldImpl&nbsp;<span style="color: #7f0055;">implements</span>&nbsp;HelloWorld{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;print(){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("HelloWorld");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//&nbsp;&nbsp;public&nbsp;void&nbsp;say(){&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Say&nbsp;Hello!");&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">C:定义一个静态代理类&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;<embed wmode="transparent" src="http://kuangbaoxu.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=package%20ttitfly.proxy%3B%20%20%20%20%0A%20%20%20%0Apublic%20class%20StaticProxy%20implements%20HelloWorld%7B%20%20%20%20%0A%20%20%20%0A%20%20%20%20public%20HelloWorld%20helloWorld%20%3B%20%20%20%20%0A%20%20%20%20public%20StaticProxy(HelloWorld%20helloWorld)%7B%20%20%20%20%0A%20%20%20%20%20%20%20%20this.helloWorld%20%3D%20helloWorld%3B%20%20%20%20%0A%20%20%20%20%7D%20%20%20%20%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20public%20void%20print()%7B%20%20%20%20%0A%20%20%20%20%20%20%20%20System.out.println(%22Welcome%22)%3B%20%20%20%20%0A%20%20%20%20%20%20%20%20%2F%2F%E7%9B%B8%E5%BD%93%E4%BA%8E%E5%9B%9E%E8%B0%83%20%20%20%20%0A%20%20%20%20%20%20%20%20helloWorld.print()%3B%20%20%20%20%0A%20%20%20%20%7D%20%20%20%20%0A%20%20%20%20%20%20%20%20%0A%2F%2F%20%20public%20void%20say()%7B%20%20%20%20%0A%2F%2F%20%20%20%20%20%20%2F%2F%E7%9B%B8%E5%BD%93%E4%BA%8E%E5%9B%9E%E8%B0%83%20%20%20%20%0A%2F%2F%20%20%20%20%20%20helloWorld.say()%3B%20%20%20%20%0A%2F%2F%20%20%7D%20%20%20%20%0A%7D%20%20%20%20" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://kuangbaoxu.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">package</span>&nbsp;ttitfly.proxy;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;StaticProxy&nbsp;<span style="color: #7f0055;">implements</span>&nbsp;HelloWorld{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;HelloWorld&nbsp;helloWorld&nbsp;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;StaticProxy(HelloWorld&nbsp;helloWorld){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">this</span>.helloWorld&nbsp;=&nbsp;helloWorld;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;print(){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Welcome");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//相当于回调&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;helloWorld.print();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//&nbsp;&nbsp;public&nbsp;void&nbsp;say(){&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//相当于回调&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;helloWorld.say();&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">D: 一个测试类:&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;<embed wmode="transparent" src="http://kuangbaoxu.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=package%20ttitfly.proxy%3B%20%20%20%20%0A%20%20%20%0Apublic%20class%20TestStaticProxy%20%7B%20%20%20%20%0A%20%20%20%0A%20%20%20%20public%20static%20void%20main(String%5B%5D%20args)%7B%20%20%20%20%0A%20%20%20%20%20%20%20%20HelloWorld%20helloWorld%20%3D%20new%20HelloWorldImpl()%3B%20%20%20%20%0A%20%20%20%20%20%20%20%20StaticProxy%20staticProxy%20%3D%20new%20StaticProxy(helloWorld)%3B%20%20%20%20%0A%20%20%20%20%20%20%20%20staticProxy.print()%3B%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%2F%2F%20%20%20%20%20%20staticProxy.say()%3B%20%20%20%20%0A%20%20%20%20%7D%20%20%20%20%0A%7D%20%20%20%20" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://kuangbaoxu.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">package</span>&nbsp;ttitfly.proxy;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;TestStaticProxy&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">static</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;main(String[]&nbsp;args){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HelloWorld&nbsp;helloWorld&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;HelloWorldImpl();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StaticProxy&nbsp;staticProxy&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;StaticProxy(helloWorld);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;staticProxy.print();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;staticProxy.say();&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">可以看出静态代理类有一个很不爽的缺点：当如果接口加一个方法（把上面所有的代码的注释给去掉），所有的实现类和代理类里都需要做个实现。这就增加了代码的复杂度。动态代理就可以避免这个缺点。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">3 。动态代理&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">动态代理与普通的代理相比较，最大的好处是接口中声明的所有方法都被转移到一个集中的方法中处理（invoke），这样，在接口方法数量比较多的时候，我们可以进行灵活处理，而不需要像静态代理那样每一个方法进行中转。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">动态代理类只能代理接口，代理类都需要实现InvocationHandler类，实现invoke方法。该invoke方法就是调用被代理接口的所有方法时需要调用的，该invoke方法返回的值是被代理接口的一个实现类&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">代理类：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;<embed wmode="transparent" src="http://kuangbaoxu.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=package%20ttitfly.proxy%3B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%0Aimport%20java.lang.reflect.InvocationHandler%3B%20%20%20%20%20%20%20%20%0Aimport%20java.lang.reflect.Method%3B%20%20%20%20%20%20%20%20%0Aimport%20java.lang.reflect.Proxy%3B%20%20%20%20%20%20%20%20%0A%2F%2F%E5%8A%A8%E6%80%81%E4%BB%A3%E7%90%86%E7%B1%BB%E5%8F%AA%E8%83%BD%E4%BB%A3%E7%90%86%E6%8E%A5%E5%8F%A3%EF%BC%8C%E4%BB%A3%E7%90%86%E7%B1%BB%E9%83%BD%E9%9C%80%E8%A6%81%E5%AE%9E%E7%8E%B0InvocationHandler%E7%B1%BB%EF%BC%8C%E5%AE%9E%E7%8E%B0invoke%E6%96%B9%E6%B3%95%E3%80%82%E8%AF%A5invoke%E6%96%B9%E6%B3%95%E5%B0%B1%E6%98%AF%E8%B0%83%E7%94%A8%E8%A2%AB%E4%BB%A3%E7%90%86%E6%8E%A5%E5%8F%A3%E7%9A%84%E6%89%80%E6%9C%89%E6%96%B9%E6%B3%95%E6%97%B6%E9%9C%80%E8%A6%81%E8%B0%83%E7%94%A8%E7%9A%84%EF%BC%8C%E8%AF%A5invoke%E6%96%B9%E6%B3%95%E8%BF%94%E5%9B%9E%E7%9A%84%E5%80%BC%E6%98%AF%E8%A2%AB%E4%BB%A3%E7%90%86%E6%8E%A5%E5%8F%A3%E7%9A%84%E4%B8%80%E4%B8%AA%E5%AE%9E%E7%8E%B0%E7%B1%BB%20%20%20%20%20%20%20%20%0Apublic%20class%20DynamicProxy%20implements%20InvocationHandler%7B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20private%20Object%20object%3B%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%2F%2F%E7%BB%91%E5%AE%9A%E5%85%B3%E7%B3%BB%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%85%B3%E8%81%94%E5%88%B0%E5%93%AA%E4%B8%AA%E6%8E%A5%E5%8F%A3%EF%BC%88%E4%B8%8E%E5%85%B7%E4%BD%93%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%E7%BB%91%E5%AE%9A%EF%BC%89%E7%9A%84%E5%93%AA%E4%BA%9B%E6%96%B9%E6%B3%95%E5%B0%86%E8%A2%AB%E8%B0%83%E7%94%A8%E6%97%B6%EF%BC%8C%E6%89%A7%E8%A1%8Cinvoke%E6%96%B9%E6%B3%95%E3%80%82%20%20%20%20%0A%20%20%20%20%2F%2FProxy.newProxyInstance%E7%9A%84%E7%AC%AC%E4%B8%89%E4%B8%AA%E5%8F%82%E6%95%B0%E6%98%AF%E8%A1%A8%E6%98%8E%E8%BF%99%E4%BA%9B%E8%A2%AB%E6%8B%A6%E6%88%AA%E7%9A%84%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E6%97%B6%E9%9C%80%E8%A6%81%E6%89%A7%E8%A1%8C%E5%93%AA%E4%B8%AAInvocationHandler%E7%9A%84invoke%E6%96%B9%E6%B3%95%20%20%20%20%0A%20%20%20%20public%20Object%20bindRelation(Object%20object)%7B%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20this.object%20%3D%20object%3B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20return%20Proxy.newProxyInstance(object.getClass().getClassLoader()%2C%20object.getClass().getInterfaces()%2Cthis)%3B%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%7D%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%2F%2F%E6%8B%A6%E6%88%AA%E5%85%B3%E8%81%94%E7%9A%84%E8%BF%99%E4%B8%AA%E5%AE%9E%E7%8E%B0%E7%B1%BB%E7%9A%84%E6%96%B9%E6%B3%95%E8%A2%AB%E8%B0%83%E7%94%A8%E6%97%B6%E5%B0%86%E8%A2%AB%E6%89%A7%E8%A1%8C%20%20%20%20%20%20%20%20%0A%20%20%20%20public%20Object%20invoke(Object%20proxy%2C%20Method%20method%2C%20Object%5B%5D%20args)%20throws%20Throwable%20%7B%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20System.out.println(%22Welcome%22)%3B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20Object%20result%20%3D%20method.invoke(object%2C%20args)%3B%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20return%20result%3B%20%20%20%20%20%20%20%20%0A%20%20%20%20%7D%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%0A%7D%20%20%20%20%20%20%20%20" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://kuangbaoxu.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">package</span>&nbsp;ttitfly.proxy;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;java.lang.reflect.InvocationHandler;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;java.lang.reflect.Method;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;java.lang.reflect.Proxy;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//动态代理类只能代理接口，代理类都需要实现InvocationHandler类，实现invoke方法。该invoke方法就是调用被代理接口的所有方法时需要调用的，该invoke方法返回的值是被代理接口的一个实现类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;DynamicProxy&nbsp;<span style="color: #7f0055;">implements</span>&nbsp;InvocationHandler{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">private</span>&nbsp;Object&nbsp;object;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//绑定关系，也就是关联到哪个接口（与具体的实现类绑定）的哪些方法将被调用时，执行invoke方法。&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//Proxy.newProxyInstance的第三个参数是表明这些被拦截的方法执行时需要执行哪个InvocationHandler的invoke方法&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;Object&nbsp;bindRelation(Object&nbsp;object){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">this</span>.object&nbsp;=&nbsp;object;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">return</span>&nbsp;Proxy.newProxyInstance(object.getClass().getClassLoader(),&nbsp;object.getClass().getInterfaces(),<span style="color: #7f0055;">this</span>);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//拦截关联的这个实现类的方法被调用时将被执行&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;Object&nbsp;invoke(Object&nbsp;proxy,&nbsp;Method&nbsp;method,&nbsp;Object[]&nbsp;args)&nbsp;<span style="color: #7f0055;">throws</span>&nbsp;Throwable&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Welcome");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;result&nbsp;=&nbsp;method.invoke(object,&nbsp;args);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">return</span>&nbsp;result;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">测试类：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;<embed wmode="transparent" src="http://kuangbaoxu.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=package%20ttitfly.proxy%3B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%0Apublic%20class%20TestDynamicProxy%20%7B%20%20%20%20%20%20%20%20%0A%20%20%20%20public%20static%20void%20main(String%5B%5D%20args)%7B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20HelloWorld%20helloWorld%20%3D%20new%20HelloWorldImpl()%3B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20DynamicProxy%20dp%20%3D%20new%20DynamicProxy()%3B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%2F%2F%E5%9C%A8%E8%BF%99%E9%87%8C%E7%BB%91%E5%AE%9A%E7%9A%84%E6%98%AFHelloWorld%2C%E4%B9%9F%E5%B0%B1%E6%98%AFHelloWorld%E6%98%AF%E8%A2%AB%E4%BB%A3%E7%90%86%E6%8E%A5%E5%8F%A3%E3%80%82%E6%89%80%E4%BB%A5%E7%BB%91%E5%AE%9A%E5%85%B3%E7%B3%BB%E6%97%B6%EF%BC%8C%E9%9C%80%E8%A6%81%E4%BC%A0%E9%80%92%E4%B8%80%E4%B8%AAHelloWorld%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BB%E7%9A%84%E5%AE%9E%E4%BE%8B%E5%8C%96%E5%AF%B9%E8%B1%A1%E3%80%82%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20HelloWorld%20helloWorld1%20%3D%20(HelloWorld)dp.bindRelation(helloWorld)%3B%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20helloWorld1.print()%3B%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20helloWorld1.say()%3B%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%2F%2FhelloWorld2%E5%B0%86%E4%B8%8D%E8%A2%AB%E6%8B%A6%E6%88%AA%20%20%20%20%0A%20%20%20%20%20%20%20%20HelloWorld%20helloWorld2%20%3D%20new%20HelloWorldImpl()%3B%20%20%20%20%0A%20%20%20%20%20%20%20%20helloWorld2.print()%3B%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20helloWorld2.say()%3B%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%7D%20%20%20%20%20%20%20%20%0A%7D%20%20%20%20%20%20%20%20" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://kuangbaoxu.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">package</span>&nbsp;ttitfly.proxy;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;TestDynamicProxy&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">static</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;main(String[]&nbsp;args){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HelloWorld&nbsp;helloWorld&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;HelloWorldImpl();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DynamicProxy&nbsp;dp&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;DynamicProxy();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//在这里绑定的是HelloWorld,也就是HelloWorld是被代理接口。所以绑定关系时，需要传递一个HelloWorld的实现类的实例化对象。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HelloWorld&nbsp;helloWorld1&nbsp;=&nbsp;(HelloWorld)dp.bindRelation(helloWorld);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;helloWorld1.print();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;helloWorld1.say();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//helloWorld2将不被拦截&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HelloWorld&nbsp;helloWorld2&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;HelloWorldImpl();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;helloWorld2.print();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;helloWorld2.say();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">在测试类里调用实现类的print和say方法，因为代理类里代理了HelloWorld的所有方法。所以就不需要像静态代理类那样一一实现了。&nbsp;</span><img src ="http://www.blogjava.net/brock/aggbug/395513.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-02-21 12:01 <a href="http://www.blogjava.net/brock/archive/2013/02/21/395513.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>理解Java对象序列化(原)</title><link>http://www.blogjava.net/brock/archive/2013/02/21/395512.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Thu, 21 Feb 2013 03:41:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/02/21/395512.html</guid><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 序列化运行时使用一个称为 serialVersionUID  的版本号与每个可序列化类相关联，该序列号在反序列化过程中用于验证序列化对象的发送者和接收者是否为该对象加载了与序列化兼容的类。如果接收者加载的该对象的类的  serialVersionUID 与对应的发送者的类的版本号不同，则反序列化将会导致 InvalidClassException。可序列化类可以通过声明名为  "serialVer...&nbsp;&nbsp;<a href='http://www.blogjava.net/brock/archive/2013/02/21/395512.html'>阅读全文</a><img src ="http://www.blogjava.net/brock/aggbug/395512.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-02-21 11:41 <a href="http://www.blogjava.net/brock/archive/2013/02/21/395512.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java泛型简明教程</title><link>http://www.blogjava.net/brock/archive/2013/02/21/395509.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Thu, 21 Feb 2013 03:31:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/02/21/395509.html</guid><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 泛型是Java SE 5.0中引入的一项特征，自从这项语言特征出现多年来，我相信，几乎所有的Java程序员不仅听说过，而且使用过它。关于Java泛型的教程，免费的，不免费的，有很多。我遇到的最好的教材有：The Java TutorialJava Generics and Collections, by Maurice Naftalin and Philip WadlerEffective Jav...&nbsp;&nbsp;<a href='http://www.blogjava.net/brock/archive/2013/02/21/395509.html'>阅读全文</a><img src ="http://www.blogjava.net/brock/aggbug/395509.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-02-21 11:31 <a href="http://www.blogjava.net/brock/archive/2013/02/21/395509.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>浅拷贝和深拷贝</title><link>http://www.blogjava.net/brock/archive/2013/02/21/395508.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Thu, 21 Feb 2013 03:03:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2013/02/21/395508.html</guid><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 浅拷贝就比如像引用类型，而深拷贝就比如值类型。&nbsp;&nbsp;浅拷贝是指源对象与拷贝对象共用一份实体，仅仅是引用的变量不同（名称不同）。对其中任何一个对象的改动都会影响另外一个对象。举个例子，一个人一开始叫张三，后来改名叫李四了，可是还是同一个人，不管是张三缺胳膊少腿还是李四缺胳膊少腿，都是这个人倒霉。深拷贝是指源对象与拷贝对象互相独立，其中任何一个对象的改动都不会对另外一个对象造成影响。...&nbsp;&nbsp;<a href='http://www.blogjava.net/brock/archive/2013/02/21/395508.html'>阅读全文</a><img src ="http://www.blogjava.net/brock/aggbug/395508.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2013-02-21 11:03 <a href="http://www.blogjava.net/brock/archive/2013/02/21/395508.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>