﻿<?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-Sun River</title><link>http://www.blogjava.net/SunRiver/</link><description>Topics about Java SE, Servlet/JSP, JDBC, MultiThread, UML, Design Pattern, CSS, JavaScript, Maven, JBoss, Tomcat, ...</description><language>zh-cn</language><lastBuildDate>Sun, 12 Apr 2026 01:15:22 GMT</lastBuildDate><pubDate>Sun, 12 Apr 2026 01:15:22 GMT</pubDate><ttl>60</ttl><item><title>Java Faqs 2</title><link>http://www.blogjava.net/SunRiver/archive/2010/10/25/336111.html</link><dc:creator>Sun River</dc:creator><author>Sun River</author><pubDate>Mon, 25 Oct 2010 09:08:00 GMT</pubDate><guid>http://www.blogjava.net/SunRiver/archive/2010/10/25/336111.html</guid><description><![CDATA[<strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">How do you delete a Cookie within a JSP? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(JSP)</p>
</font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Answer</p>
</strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">
<p align="left">Cookie mycook = new Cookie("name","value");</p>
<p align="left">response.addCookie(mycook);</p>
<p align="left">Cookie killmycook = new Cookie("mycook","value");</p>
<p align="left">killmycook.setMaxAge(0);</p>
<p align="left">killmycook.setPath("/");</p>
<p>killmycook.addCookie(killmycook);</p>
</font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">How many types of protocol implementations does RMI have? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(RMI)</p>
<strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">RMI has at least three protocol implementations: Java</p>
<p align="left">Remote Method Protocol(JRMP), Internet Inter ORB Protocol(IIOP),</p>
<p align="left">and Jini Extensible Remote Invocation(JERI). These are alternatives,</p>
<p align="left">not part of the same thing, All three are indeed layer 6 protocols for</p>
<p>those who are still speaking OSI reference model.<br />
<strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold"></p>
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">What are the different identifier states of a Thread?</p>
<p></font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"></p>
<p align="left">(Core Java)</p>
<p></font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold"></p>
<p align="left">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">The different identifiers of a Thread are:</p>
<p align="left">R - Running or runnable thread</p>
<p align="left">S - Suspended thread</p>
<p align="left">CW - Thread waiting on a condition variable</p>
<p align="left">MW - Thread waiting on a monitor lock</p>
<p>MS - Thread suspended waiting on a monitor lock</p>
</font></font><br />
<strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">What is the fastest type of JDBC driver? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(JDBC)</p>
</font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">JDBC driver performance will depend on a number of</p>
<p align="left">issues:</p>
<p align="left">(a) the quality of the driver code,</p>
<p align="left">(b) the size of the driver code,</p>
<p align="left">(c) the database server and its load,</p>
<p align="left">(d) network topology,</p>
<p align="left">(e) the number of times your request is translated to a different API.</p>
<p align="left">In general, all things being equal, you can assume that the more your</p>
<p>request and response change hands, the slower it will be. This</p>
</font></font><font size="4" face="Arial"><font size="4" face="Arial">
<p align="left">means that Type 1 and Type 3 drivers will be slower than Type 2</p>
<p align="left">drivers (the database calls are make at least three translations versus</p>
<p align="left">two), and Type 4 drivers are the fastest (only one translation).</p>
</font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">Request parameter How to find whether a parameter</p>
<p align="left">exists in the request object? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(Servlets)</p>
</font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">1.boolean hasFoo = !(request.getParameter("foo") ==</p>
<p align="left">null || request.getParameter("foo").equals(""));</p>
<p align="left">2. boolean hasParameter =</p>
<p align="left">request.getParameterMap().contains(theParameter);</p>
<p>(which works in Servlet 2.3+)</p>
</font></font><br />
<strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">How can I send user authentication information while</p>
<p align="left">makingURLConnection? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(Servlets)</p>
</font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">You&#8217;ll want to use</p>
<p align="left">HttpURLConnection.setRequestProperty and set all the appropriate</p>
<p>headers to HTTP authorization.</p>
<strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">How do I convert a numeric IP address like 192.18.97.39</p>
<p align="left">into a hostname like java.sun.com? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(Networking)</p>
</font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Answer <strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold"></p>
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">How many methods do u implement if implement the</p>
<p align="left">Serializable Interface? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(Core Java)</p>
<p align="left"></font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold"></p>
<p align="left">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">The Serializable interface is just a "marker" interface,</p>
<p align="left">with no methods of its own to implement. Other &#8217;marker&#8217; interfaces</p>
<p align="left">are</p>
<p align="left">java.rmi.Remote</p>
<p>java.util.EventListener</p>
<p align="left"></font></font></strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">String hostname =InetAddress.getByName("192.18.97.39").getHostName();</p>
</font></font></font></font></font></font></font></font></font>
<img src ="http://www.blogjava.net/SunRiver/aggbug/336111.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/SunRiver/" target="_blank">Sun River</a> 2010-10-25 17:08 <a href="http://www.blogjava.net/SunRiver/archive/2010/10/25/336111.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java Faqs 1</title><link>http://www.blogjava.net/SunRiver/archive/2010/10/25/336099.html</link><dc:creator>Sun River</dc:creator><author>Sun River</author><pubDate>Mon, 25 Oct 2010 08:07:00 GMT</pubDate><guid>http://www.blogjava.net/SunRiver/archive/2010/10/25/336099.html</guid><description><![CDATA[1. <strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">What is the query used to display all tables names in</p>
<p align="left">SQL Server (Query analyzer)? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(JDBC)</p>
</font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Answer </strong></font></font><font size="4" face="Courier"><font size="4" face="Courier">select * from information_schema.tables</p>
</font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p>Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">What is Externalizable? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(Core Java)</p>
</font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">Externalizable is an Interface that extends Serializable</p>
<p align="left">Interface. And sends data into Streams in Compressed Format. It has</p>
<p align="left">two methods, writeExternal(ObjectOuput out) and</p>
<p>readExternal(ObjectInput in).</p>
<strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">What modifiers are allowed for methods in an Interface?</p>
</font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">Only public and abstract modifiers are allowed for</p>
<p>methods in interfaces.</p>
</font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">How many types of JDBC Drivers are present and what</p>
<p align="left">are they? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(JDBC)</p>
</font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">There are 4 types of JDBC Drivers</p>
<p align="left">Type 1: JDBC-ODBC Bridge Driver</p>
<p align="left">Type 2: Native API Partly Java Driver</p>
<p align="left">Type 3: Network protocol Driver</p>
<p align="left">Type 4: JDBC Net pure Java Driver</p>
</font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold"><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">What is the difference between ServletContext and</p>
<p align="left">PageContext? </font></font><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial"><font color="#810000" size="4" face="Arial">(JSP)</p>
<p></font></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">ServletContext: Gives the information about the container</p>
<p>PageContext: Gives the information about the Request.<br />
<strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold"></p>
<p align="left">Question </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">How to pass information from JSP to included JSP?</p>
<p></font></font><strong><font size="4" face="Arial,Bold"><font size="4" face="Arial,Bold">Answer </strong></font></font><font size="4" face="Arial"><font size="4" face="Arial">Using &lt;%jsp:param&gt; tag.</font></font></font></font></strong></font></font></font></font></p>
<img src ="http://www.blogjava.net/SunRiver/aggbug/336099.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/SunRiver/" target="_blank">Sun River</a> 2010-10-25 16:07 <a href="http://www.blogjava.net/SunRiver/archive/2010/10/25/336099.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>tomcat6配置https</title><link>http://www.blogjava.net/SunRiver/archive/2010/05/11/320579.html</link><dc:creator>Sun River</dc:creator><author>Sun River</author><pubDate>Tue, 11 May 2010 04:12:00 GMT</pubDate><guid>http://www.blogjava.net/SunRiver/archive/2010/05/11/320579.html</guid><description><![CDATA[<h3>&nbsp;
<p><span style="font-size: 11pt">tomcat6</span><span style="font-family: SimSun; font-size: 11pt">配置双向认证</span><span style="font-size: 11pt"> <br />
<br />
1</span><span style="font-family: SimSun; font-size: 11pt">、生成服务器端证书</span><span style="font-size: 11pt"><br />
<br />
</span></p>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">keytool -genkey -keyalg RSA -dname "cn=localhost,ou=sango,o=none,l=china,st=</span><span style="font-family: 'Times New Roman'; font-size: 11pt">beijing</span><span style="font-family: 'Times New Roman'; font-size: 11pt">,c=cn" -alias server -keypass password -keystore server.jks -storepass password -validity 3650</span></pre>
<p><span style="font-size: 11pt"><br />
2</span><span style="font-family: SimSun; font-size: 11pt">、生成客户端证书</span><span style="font-size: 11pt"><br />
<br />
</span></p>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">keytool -genkey -keyalg RSA -dname "cn=sango,ou=sango,o=none,l=china,st=</span><span style="font-family: 'Times New Roman'; font-size: 11pt">beijing</span><span style="font-family: 'Times New Roman'; font-size: 11pt">,c=cn" -alias custom -storetype PKCS12 -keypass password -keystore custom.p12 -storepass password -validity 3650</span></pre>
<p><span style="font-size: 11pt"><br />
</span><span style="font-family: SimSun; font-size: 11pt">客户端的</span><span style="font-size: 11pt">CN</span><span style="font-family: SimSun; font-size: 11pt">可以是任意值。</span><span style="font-size: 11pt"> <br />
3</span><span style="font-family: SimSun; font-size: 11pt">、由于是双向</span><span style="font-size: 11pt">SSL</span><span style="font-family: SimSun; font-size: 11pt">认证，服务器必须要信任客户端证书，因此，必须把客户端证书添加为服务器的信任认证。由于不能直接将</span><span style="font-size: 11pt">PKCS12</span><span style="font-family: SimSun; font-size: 11pt">格式的证书库导入，我们必须先把客户端证书导出为一个单独的</span><span style="font-size: 11pt">CER</span><span style="font-family: SimSun; font-size: 11pt">文件，使用如下命令，先把客户端证书导出为一个单独的</span><span style="font-size: 11pt">cer</span><span style="font-family: SimSun; font-size: 11pt">文件：</span><span style="font-size: 11pt"><br />
<br />
</span></p>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">keytool -export -alias custom -file custom.cer -keystore&nbsp;custom.p12 -storepass password -storetype PKCS12 -rfc</span></pre>
<p><span style="font-size: 11pt"><br />
</span><span style="font-family: SimSun; font-size: 11pt">然后，添加客户端证书到服务器中（将已签名数字证书导入密钥库）</span><span style="font-size: 11pt"><br />
<br />
</span></p>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">keytool -import -v -alias custom -file custom.cer -keystore&nbsp;server.jks -storepass password</span></pre>
<p><span style="font-size: 11pt"><br />
4</span><span style="font-family: SimSun; font-size: 11pt">、查看证书内容</span><span style="font-size: 11pt"><br />
<br />
</span></p>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">keytool -list -v -keystore server.jks -storepass password</span></pre>
<p><span style="font-size: 11pt"><br />
5</span><span style="font-family: SimSun; font-size: 11pt">、配置</span><span style="font-size: 11pt">tomcat service.xml</span><span style="font-family: SimSun; font-size: 11pt">文件</span><span style="font-size: 11pt"><br />
<br />
</span></p>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">&lt;Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"</span></pre>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">&nbsp;&nbsp;&nbsp; maxThreads="150" scheme="https" secure="true"</span></pre>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">&nbsp;&nbsp;&nbsp; clientAuth="true" sslProtocol="TLS"</span></pre>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">&nbsp;&nbsp;&nbsp; keystoreFile="D:/server.jks" keystorePass="password"</span></pre>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">&nbsp;&nbsp;&nbsp; truststoreFile="D:/server.jks" truststorePass="password"</span></pre>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">/&gt;</span></pre>
<p><span style="font-size: 11pt"><br />
clientAuth="true"</span><span style="font-family: SimSun; font-size: 11pt">表示双向认证</span><span style="font-size: 11pt"> <br />
6</span><span style="font-family: SimSun; font-size: 11pt">、导入客户端证书到浏览器</span><span style="font-size: 11pt"> <br />
</span><span style="font-family: SimSun; font-size: 11pt">双向认证需要强制验证客户端证书。双击</span><span style="font-size: 11pt">&#8220;custom.p12&#8221;</span><span style="font-family: SimSun; font-size: 11pt">即可将证书导入至</span><span style="font-size: 11pt">IE <br />
<br />
tomcat6</span><span style="font-family: SimSun; font-size: 11pt">配置单向认证</span><span style="font-size: 11pt"> <br />
<br />
1</span><span style="font-family: SimSun; font-size: 11pt">、生成服务器端证书</span><span style="font-size: 11pt"><br />
<br />
</span></p>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">keytool -genkey -keyalg RSA -dname "cn=localhost,ou=sango,o=none,l=china,st=</span><span style="font-family: 'Times New Roman'; font-size: 11pt">beijing</span><span style="font-family: 'Times New Roman'; font-size: 11pt">,c=cn" -alias server -keypass password -keystore server.jks -storepass password -validity 3650</span></pre>
<p><span style="font-size: 11pt"><br />
2</span><span style="font-family: SimSun; font-size: 11pt">、由于是单向认证，没有必要生成客户端的证书，直接进入配置</span><span style="font-size: 11pt">tomcat service.xml</span><span style="font-family: SimSun; font-size: 11pt">文件</span><span style="font-size: 11pt"><br />
<br />
</span></p>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">&lt;Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"</span></pre>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">&nbsp;&nbsp;&nbsp; maxThreads="150" scheme="https" secure="true"</span></pre>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">&nbsp;&nbsp;&nbsp; clientAuth="false" sslProtocol="TLS"</span></pre>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">&nbsp;&nbsp;&nbsp; keystoreFile="D:/server.jks" keystorePass="password"&nbsp;&nbsp;&nbsp; </span></pre>
<pre><span style="font-family: 'Times New Roman'; font-size: 11pt">/&gt;</span></pre>
<p><span style="font-size: 11pt"><br />
clientAuth="false"</span><span style="font-family: SimSun; font-size: 11pt">表示单向认证，同时去掉</span><span style="font-size: 11pt">truststoreFile="D:/server.jks" truststorePass="password"</span><span style="font-family: SimSun; font-size: 11pt">这</span><span style="font-size: 11pt">2</span></p>
</h3>
<img src ="http://www.blogjava.net/SunRiver/aggbug/320579.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/SunRiver/" target="_blank">Sun River</a> 2010-05-11 12:12 <a href="http://www.blogjava.net/SunRiver/archive/2010/05/11/320579.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Difference between class and id in CSS</title><link>http://www.blogjava.net/SunRiver/archive/2010/03/16/315552.html</link><dc:creator>Sun River</dc:creator><author>Sun River</author><pubDate>Tue, 16 Mar 2010 02:14:00 GMT</pubDate><guid>http://www.blogjava.net/SunRiver/archive/2010/03/16/315552.html</guid><description><![CDATA[&nbsp;
<p><span style="font-family: Verdana; color: blue; font-size: 9pt">---The key thing to know is that IDs identify a specific element and therefore must be unique on the page &#8211; you can only use a specific ID once per document. Many browsers do not enforce this rule but it is a basic rule of <acronym><span style="font-family: Verdana">HTML</span></acronym>/<acronym><span style="font-family: Verdana">XHTML</span></acronym> and should be observed. Classes mark elements as members of a group and can be used multiple times, so if you want to define a style which will be applied to multiple elements you should use a class instead.</span></p>
<p><span style="font-family: Verdana; color: blue; font-size: 9pt">&nbsp;</span><span style="font-family: Arial; color: black; font-size: 9.5pt">Notice that an ID's CSS is an HTML element, followed by a "#", and finally ID's name. The end result looks something like "element#idname". Also, be sure to absorb the fact that when an ID is used in HTML, we must use "id=name" instead of "class=name" to reference it!</span></p>
<div style="border-bottom: #0a4369 1pt dotted; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm">
<h1><span style="font-family: Arial; font-size: 17pt">Why Did They Choose Those Names??</span></h1>
</div>
<p style="text-indent: -18pt; margin-left: 36pt; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-family: Symbol; color: black; font-size: 10pt"><span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span dir="ltr"><span style="font-family: Arial; color: black; font-size: 9.5pt">ID = A person's Identification (ID) is <strong>unique</strong> to one person.</span></span></p>
<p style="text-indent: -18pt; margin-left: 36pt; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-family: Symbol; color: black; font-size: 10pt"><span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span dir="ltr"><span style="font-family: Arial; color: black; font-size: 9.5pt">Class = There are <strong>many</strong> people in a class.</span></span></p>
<div style="border-bottom: #0a4369 1pt dotted; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm">
<h1><span style="font-family: Arial; font-size: 17pt">ID for Layout and Uniqueness</span></h1>
</div>
<p><span style="font-family: Arial; color: black; font-size: 9.5pt">Standards specify that any given ID name can only be referenced once within a page or document. From our experience, IDs are most commonly used correctly in CSS layouts. This makes sense because there are usually only one menu per page, one banner, and usually only one content pane.</span></p>
<p><span style="font-family: Arial; color: black; font-size: 9.5pt">In Tizag.com <a href="http://www.tizag.com/cssT/liveExampleCss/"><span style="font-size: 8.5pt">CSS Layout Examples</span></a> we have used IDs for the unique items mentioned above. <a href="http://www.tizag.com/cssT/liveExampleCss/style1Css.php"><span style="font-size: 8.5pt">View the CSS Code</span></a> for our first layout example. Below are the unique IDs in our code.</span></p>
<p style="text-indent: -18pt; margin-left: 36pt; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-family: Symbol; color: black; font-size: 10pt"><img alt="*" src="PicExportError" width="10" height="10" /><span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span dir="ltr"><span style="font-family: Arial; color: black; font-size: 9.5pt">Menu - div#menuPane</span></span></p>
<p style="text-indent: -18pt; margin-left: 36pt; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-family: Symbol; color: black; font-size: 10pt"><img alt="*" src="PicExportError" width="10" height="10" /><span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span dir="ltr"><span style="font-family: Arial; color: black; font-size: 9.5pt">Content - div#content</span></span></p>
<div style="border-bottom: #0a4369 1pt dotted; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm">
<h1><span style="font-family: Arial; font-size: 17pt">Answer: Classes vs IDs</span></h1>
</div>
<p><span style="font-family: Arial; color: black; font-size: 9.5pt">Use IDs when there is only one occurence per page. Use classes when there are one or more occurences per page.</span></p>
<img src ="http://www.blogjava.net/SunRiver/aggbug/315552.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/SunRiver/" target="_blank">Sun River</a> 2010-03-16 10:14 <a href="http://www.blogjava.net/SunRiver/archive/2010/03/16/315552.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> Web中singleton的范围,spring中singleton的范围</title><link>http://www.blogjava.net/SunRiver/archive/2009/04/08/264426.html</link><dc:creator>Sun River</dc:creator><author>Sun River</author><pubDate>Wed, 08 Apr 2009 04:12:00 GMT</pubDate><guid>http://www.blogjava.net/SunRiver/archive/2009/04/08/264426.html</guid><description><![CDATA[--Spring的singleton是容器级的，我们一般说的singleton模式是JVM级的。所以singleton模式中，singleton的class在整个JVM中只有一个instance，Spring的Bean，你可以一个class配置多个Bean，这个class就有了多个instance。这个singleton是指在spring容器中，这个Bean是单实例的，是线程共享的。所以要求这些类都是线程安全的。也就是说，不能出现修改Bean属性的方法，当然除了设值得那些setter。只要满足线程安全，这些bean都可以用singleton。而且我们在绝大多数使用上，也是这样用的，包括dao,service。<br />
Beanfactory是Spring初始以静态方式载入的,Spring的单例IOC是基于容器级的,所以这你都不用担心与考虑.<br />
<br />
--应用中对象有两种，行为对象和数据对象，行为对象都要求是线程安全的！也就是允许单例的, 不管是dao 还是 service 对象，都是行为对象，行为对象不应该引用非线程安全的对象做成员量，同时在应用外部的资源（如文件，数据库连接，session）时，要先保证对这些东西的访问是做了并发控制的！<br />
&nbsp; 对于spring来讲，&lt;bean scope="singleton"/&gt;或&lt;bean singleton="true"/&gt;都是保证对同一sesionfactory bean是单例的，也就是所谓 sessionfactory 范围的.<br />
<br />
--这是一个真实的案例，我们在项目中使用Spring和ACEGI,我之所以选择ACEGI，除了它对权限的良好控制外， <br />
我还看好它的SecurityContextHolder，通过代码 <br />
<div class="code_title">代码</div>
<div class="code_div">
<div class="dp-highlighter">
<ol class="dp-j">
    <li class="alt"><span><span>Authentication&nbsp;auth&nbsp;=&nbsp;SecurityContextHolder.getContext().getAuthentication(); &nbsp;&nbsp;</span></span> </li>
</ol>
</div>
</div>
&lt;script&gt;render_code();&lt;/script&gt;<br />
我可以很容易在系统任意一层得到用户的信息，而不用把用户信息在参数里传来传去，(这也是struts的缺点之一) <br />
但是我在每一次要得到用户信息的时候都写上面的一段代码，未免有些麻烦，所以我在BaseService, BaseDao里都提供了如下方法： <br />
<div class="code_title">代码</div>
<div class="code_div">
<div class="dp-highlighter">
<div class="bar">
<ol class="dp-j">
    <li class="alt"><span><span>&nbsp;</span><span class="comment">/** </span>&nbsp;</span>
    <li class=""><span><span class="comment">&nbsp;*&nbsp;get&nbsp;current&nbsp;login&nbsp;user&nbsp;info </span>&nbsp;</span>
    <li class="alt"><span><span class="comment">&nbsp;*&nbsp;@return&nbsp;UserInfo </span>&nbsp;</span>
    <li class=""><span><span class="comment">&nbsp;*/</span><span>&nbsp;&nbsp;</span></span>
    <li class="alt"><span><span class="keyword">protected</span><span>&nbsp;UserInfo&nbsp;getUserInfo() &nbsp;&nbsp;</span>
    <li class=""><span>{ &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span>&nbsp;getUserContext().getUserInfo(); &nbsp;&nbsp;</span>
    <li class=""><span>} &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;</span>
    <li class=""><span><span class="comment">/** </span>&nbsp;
    <li class="alt"><span><span class="comment">&nbsp;*&nbsp;get&nbsp;current&nbsp;login&nbsp;user&nbsp;context </span>&nbsp;</span>
    <li class=""><span><span class="comment">&nbsp;*&nbsp;@return&nbsp;UserContext </span>&nbsp;</span>
    <li class="alt"><span><span class="comment">&nbsp;*/</span><span>&nbsp;&nbsp;</span></span>
    <li class=""><span><span class="keyword">protected</span><span>&nbsp;UserContext&nbsp;getUserContext() &nbsp;&nbsp;</span>
    <li class="alt"><span>{ &nbsp;&nbsp;</span>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;Authentication&nbsp;auth&nbsp;=&nbsp;SecurityContextHolder.getContext().getAuthentication(); &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span>&nbsp;(UserContext)&nbsp;auth.getPrincipal(); &nbsp;&nbsp;</span>
    <li class=""><span>} &nbsp;&nbsp;</span> </li>
</ol>
</div>
</div>
&lt;script&gt;render_code();&lt;/script&gt;<br />
这样在其他的Service和Dao类里可以通过 <br />
<div class="code_title">代码</div>
<div class="code_div">
<div class="dp-highlighter">
<div class="bar">
<ol class="dp-j">
    <li class="alt"><span><span class="keyword">super</span><span>.getUserContext(),&nbsp;</span><span class="keyword">super</span><span>.getUserInfo() &nbsp;&nbsp;</span></span> </li>
</ol>
</div>
</div>
&lt;script&gt;render_code();&lt;/script&gt;<br />
来得到用户的信息，这也为问题的产生提供了温床。请看如下代码： <br />
<div class="code_title">代码</div>
<div class="code_div">
<div class="dp-highlighter">
<div class="bar">
<ol class="dp-j">
    <li class="alt"><span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;SomeServece&nbsp;</span><span class="keyword">extends</span><span>&nbsp;BaseService&nbsp;</span><span class="keyword">implements</span><span>&nbsp;SomeInterFace&nbsp;&nbsp; &nbsp;&nbsp;</span></span>
    <li class=""><span>{ &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">private</span><span>&nbsp;UserInfo&nbsp;user&nbsp;=&nbsp;</span><span class="keyword">super</span><span>.getUserInfo(); &nbsp;&nbsp;</span>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;someMethod() &nbsp;&nbsp;</span>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;userID&nbsp;=&nbsp;</span><span class="keyword">this</span><span>.user.getUserID(); &nbsp;&nbsp;</span>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;userName&nbsp;=&nbsp;</span><span class="keyword">this</span><span>.user.getUserName(); &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//bla&nbsp;bla&nbsp;do&nbsp;something&nbsp;user&nbsp;userID&nbsp;and&nbsp;userNaem </span><span>&nbsp;&nbsp;</span>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span>
    <li class="alt"><span>}&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</span> </li>
</ol>
</div>
</div>
&lt;script&gt;render_code();&lt;/script&gt;
<p>&nbsp;</p>
<p>这段代码在单元测试的时候不会用任何问题，但是在多用户测试的情况下，你会发现任何调用SomeService里someMethod()方法 <br />
的userID和userName都是同一个人，也就是第一个登陆的人的信息。Why? <br />
<strong><br />
其根本原因是Spring的Bean在默认情况下是Singleton的，Bean SomeServece的实例只会生成一份，也就是所SomeServece实例的user <br />
对象只会被初始化一次，就是第一次登陆人的信息，以后不会变了。所以BaseService想为开发提供方便，却给开发带来了风险 <br />
</strong><br />
正确的用法应该是这样的 <br />
</p>
<div class="code_title">代码</div>
<div class="code_div">
<div class="dp-highlighter">
<div class="bar">
<ol class="dp-j">
    <li class="alt"><span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;SomeServece&nbsp;</span><span class="keyword">extends</span><span>&nbsp;BaseService&nbsp;</span><span class="keyword">implements</span><span>&nbsp;SomeInterFace&nbsp;&nbsp; &nbsp;&nbsp;</span></span>
    <li class=""><span>{ &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</span>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;someMethod() &nbsp;&nbsp;</span>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;userID&nbsp;=&nbsp;</span><span class="keyword">super</span><span>.getUserInfo().getUserID(); &nbsp;&nbsp;</span>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;userName&nbsp;=&nbsp;</span><span class="keyword">super</span><span>.getUserInfo().getUserName(); &nbsp;&nbsp;</span>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//bla&nbsp;bla&nbsp;do&nbsp;something&nbsp;user&nbsp;userID&nbsp;and&nbsp;userNaem </span><span>&nbsp;&nbsp;</span>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span> </li>
</ol>
</div>
</span></span></span></div>
</div>
</div>
</div>
</div>
<img src ="http://www.blogjava.net/SunRiver/aggbug/264426.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/SunRiver/" target="_blank">Sun River</a> 2009-04-08 12:12 <a href="http://www.blogjava.net/SunRiver/archive/2009/04/08/264426.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java Architect Issue -2-</title><link>http://www.blogjava.net/SunRiver/archive/2009/03/17/260207.html</link><dc:creator>Sun River</dc:creator><author>Sun River</author><pubDate>Tue, 17 Mar 2009 03:51:00 GMT</pubDate><guid>http://www.blogjava.net/SunRiver/archive/2009/03/17/260207.html</guid><description><![CDATA[<h1 align="center"><font face="Comic Sans MS">Architect (Java) Interview Questions</font></h1>
<h3>General and general terms questions</h3>
Architect interview is slightly different from all other interview types. Interviewer is looking for ability of the candidate to think independently on top of pure technical knowledge. Most of the questions are open-ended, prompting the interviewee to discussion about different aspects of Java development. Other side of the interview is general questions about position of the architect within the organization. Some questions do not have clear, direct or single answer and require discussion with the interviewer. On top of questions mentioned here you may be asked generic OO questions (what is class, what is polymorphism etc.)
<ol type="square">
    <li child="jarch_001">What distinguishes "good architecture" from "bad architecture"?
    <div id="jarch_001">This is an open-ended question. There are few aspects of "good" architecture:
    <ol>
        <li class="nostyle">Shall address functional product requirements
        <li class="nostyle">Shall address non-functional product requirements, such as performance, scalability, reliability, fault tolerance, availability, maintainability, extensibility
        <li class="nostyle">Shall be simple and comprehendible (to support maintainability and extensibility)
        <li class="nostyle">Shall be well structured (support multiple tiers, parallel development etc.)
        <li class="nostyle">Shall be detailed enough to share with different levels of organizational structure (marketing, sales, development, management) </li>
    </ol>
    "Bad" architecture is basically opposite to "good" architecture. </div>
    <li child="jarch_002">How much experience do you have with Enterprise applications? Another variant of this questions is: "Tell me about projects where you worked with J2EE?" Yet another version: "What, when and how made using EJB?"
    <div id="jarch_002">Interviewer is looking for your experience with designing J2EE applications and your experience with J2EE technologies and general terms. This is often start of the discussion and bridge to the technical section of the questions.</div>
    <li child="jarch_004">What is scalability?
    <div id="jarch_004"></div>
    <li child="jarch_005">What is high-availability? How is it different from scalability?
    <div id="jarch_005"></div>
    <li child="jarch_006">What is the fault tolerance?
    <div id="jarch_006"></div>
    <li child="jarch_007">What resources are used to keep up to date with J2EE technology?
    <div id="jarch_007">You may mention design pattern books, such as "Core EJB Patterns" and web sites, such as <a href="http://www.theserverside.com/">http://www.theserverside.com</a></div>
    </li>
</ol>
<h3>Specific technical questions</h3>
<ol type="square">
    <li child="jarch_tech_001">What modeling tools you are familiar with? What version of TogetherJ (Rational Rose etc.) have you used?
    <div id="jarch_tech_001"></div>
    <li child="jarch_tech_002">If stateless session bean more scalable than stateful session beans?
    <div id="jarch_tech_002">This is very popular questions that leads to some confusion. According to the second edition of "Core J2EE Patterns" and contrary to popular belief, stateful session beans are not less scalable than stateless session bean. The reason for that is life cycle of either type is controlled by Application Server and control of life cycle is what defines the scalability of the application</div>
    <li child="jarch_tech_003">What's the difference between EJB 1.1 and EJB 2.0?
    <div id="jarch_tech_003">There are many differences. Some key points you want to mention are:
    <ol>
        <li class="nostyle">New CMP model
        <li class="nostyle">EJB Query Language
        <li class="nostyle">Local interfaces
        <li class="nostyle">EJBHome methods
        <li class="nostyle">Message Driven Beans (MDB) support </li>
    </ol>
    </div>
    <li child="jarch_tech_004">What transaction isolation levels do you know?
    <div id="jarch_tech_004">none, repeatable read, read committed, read uncommitted, serializable</div>
    <li child="jarch_tech_005">What transaction attributes do you know?
    <div id="jarch_tech_005">requires new, required, supports, not supported, mandatory, never</div>
    <li child="jarch_tech_006">What is the difference between optimistic lock and pessimistic lock?
    <div id="jarch_tech_006">Optimistic lock is an implicit lock that tries to make best assumption about locking strategy and minimize time spent in lock of resource. Optimistic lock is usually implemented with some kind of timestamp strategy. Pessimistic lock is an explicit lock that set by client.</div>
    <li child="jarch_tech_007">What are entity beans. Are there any issues with them?
    <div id="jarch_tech_007">Typical reaction to this question is very expressive answer that entity beans should not be used. There are many performancy implications with entity beans if used incorrectly. One of the famous problems are "n+1 call problem" Inter-entity bean call is very expensive operation and should be avoided.</div>
    <li child="jarch_tech_008">What core design patterns do you know?
    <div id="jarch_tech_008">Architect must know at least some basic design patters used in J2EE development, e.g. Business Delegate, Session Facade, VO, List Handler, DTO, Composite Entity, etc.</div>
    <li child="jarch_tech_009">Where business logic should reside?
    <div id="jarch_tech_009">Typical answer is "in business tier" This usually opens series of questions like: What is business logic, how to determine business logic, how business logic is different from persistent logic etc.</div>
    <li child="jarch_tech_010">What is JDO?
    <div id="jarch_tech_010">JDO is Java Data Object - persistent framework that is alternative to idea of entity beans</div>
    <li child="jarch_tech_011">What is the difference between JSP and servlet? When to use what?
    <div id="jarch_tech_011">JSP is compiled into servlet. JSP are better suit to view of information, while servlets are better for controlling stuff.</div>
    <li child="jarch_tech_012">Does the J2EE platform support nested transactions?
    <div id="jarch_tech_012">No.</div>
    <li child="jarch_tech_013">Can you use synchronization primitives in my enterprise beans?
    <div id="jarch_tech_013">No.</div>
    <li child="jarch_tech_014">Why all major application server vendors provide custom class loaders in addition to system jvm class loader?
    <div id="jarch_tech_014">System one does not support hot deployment.</div>
    </li>
</ol>
<h3>Performance questions</h3>
<ol type="square">
    <li child="jarch_perf_001">What are performance problems in J2EE and how to solve them?
    <div id="jarch_perf_001"></div>
    <li child="jarch_perf_002">What are Entity beans performance pitfalls?
    <div id="jarch_perf_002"></div>
    <li child="jarch_perf_003">What performance pattern do you know?
    <div id="jarch_perf_003"></div>
    </li>
</ol>
<h3>Design Pattern questions</h3>
<ol type="square">
    <li child="jarch_dp_001">Can you use singleton in EJB?
    <div id="jarch_dp_001">Yes, but should not (explain why)</div>
    <li child="jarch_dp_002">What is MVC pattern and why M, V and C need to be separated?
    <div id="jarch_dp_002"></div>
    <li child="jarch_dp_003">Describe Business Delegate pattern (or any other pattern)
    <div id="jarch_dp_003"></div>
    <li child="jarch_dp_004">How to prevent double submission of the form from JSP page? (or describe Synchronizer Token pattern)
    <div id="jarch_dp_004"></div>
    </li>
</ol>
<!--msnavigation-->
<img src ="http://www.blogjava.net/SunRiver/aggbug/260207.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/SunRiver/" target="_blank">Sun River</a> 2009-03-17 11:51 <a href="http://www.blogjava.net/SunRiver/archive/2009/03/17/260207.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Interview Questions on UML and Design Patterns</title><link>http://www.blogjava.net/SunRiver/archive/2009/03/17/260205.html</link><dc:creator>Sun River</dc:creator><author>Sun River</author><pubDate>Tue, 17 Mar 2009 03:43:00 GMT</pubDate><guid>http://www.blogjava.net/SunRiver/archive/2009/03/17/260205.html</guid><description><![CDATA[<p><strong>Interview Questions on UML and Design Patterns</strong><br />
<br />
Why to use design patterns?<br />
Give examples of design patterns?<br />
What is UML?<br />
What are advantages of using UML?<br />
What is the need for modelling?<br />
Is it requiste to use UML in software projects?<br />
What are use cases? How did you capture use cases in your project?<br />
Explain the different types of UML diagrams ? sequence diagram , colloboration diagram etc<br />
What is the sequence of UML diagrams in project?<br />
What tools did you use for UML in your project?<br />
What is the difference between activity and sequence diagrams?<br />
What are deployment diagrams?<br />
What are the different object relationships ?<br />
What is the difference between composition and aggregation?<br />
Wheel acting as a part of car ? Is this composition or aggregation?<strong></strong></p>
<img src ="http://www.blogjava.net/SunRiver/aggbug/260205.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/SunRiver/" target="_blank">Sun River</a> 2009-03-17 11:43 <a href="http://www.blogjava.net/SunRiver/archive/2009/03/17/260205.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>spring与自动调度任务 </title><link>http://www.blogjava.net/SunRiver/archive/2009/03/12/259312.html</link><dc:creator>Sun River</dc:creator><author>Sun River</author><pubDate>Thu, 12 Mar 2009 04:42:00 GMT</pubDate><guid>http://www.blogjava.net/SunRiver/archive/2009/03/12/259312.html</guid><description><![CDATA[&nbsp;
<p style="background: white; vertical-align: top; line-height: 150%"><span style="font-family: Arial"><a href="http://www.blogjava.net/duduli/archive/2009/03/10/258793.html">spring<span style="font-family: SimSun">与自动调度任务</span>(<span style="font-family: SimSun">一</span>)</a> </span></p>
<p style="background: white; vertical-align: top; line-height: 150%"><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">面是自己自动调度的一些学习。</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial"><br />
</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">这里只采用</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">jdk</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">自带的</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">timer</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">进行的，准备在下篇文章中用</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">Quartz</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">调度器。</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial"><br />
</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">首先建立你自己要运行的类。</span></p>
<p style="background: #eeeeee; vertical-align: top; word-break: break-all; line-height: 150%"><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">package</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;com.duduli.li;<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">class</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;Display&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">void</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;disp(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: SimSun">自动控制测试</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</span></p>
<p style="background: white; vertical-align: top; line-height: 150%"><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">一个简单的</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">java bean</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">，其中在这里你可以替换自己的任务。</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial"><br />
</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">然后就是编写调度程序，这里要继承</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">jdk</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">中的</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">TimerTask</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">类，复写他的</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">run</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">方法。</span></p>
<p style="background: #eeeeee; vertical-align: top; word-break: break-all; line-height: 150%"><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">package</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;com.duduli.li;<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">import</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;java.util.TimerTask;<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">class</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;AutoRan&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">extends</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;TimerTask&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">//set</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">方法是</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">spring</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">的</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">DI<br />
</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">private</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;Display&nbsp;display;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">void</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;setDisplay(Display&nbsp;display)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">this</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">.display&nbsp;=&nbsp;display;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">void</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;run()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.disp();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</span></p>
<p style="background: white; vertical-align: top; line-height: 150%"><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">然后就是重要的一步，编写</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">applicationsContext.xml</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">了。</span></p>
<p style="background: #eeeeee; vertical-align: top; word-break: break-all; line-height: 150%"><span style="font-size: 10pt; line-height: 150%; font-family: Arial"><span style="color: blue">&lt;?</span><span style="color: fuchsia">xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"</span><span style="color: blue">?&gt;</span><span style="color: black"><br />
</span><span style="color: blue">&lt;</span><span style="color: maroon">beans<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: red">xmlns</span><span style="color: blue">="http://www.springframework.org/schema/beans"</span><span style="color: red"><br />
&nbsp;&nbsp;&nbsp;&nbsp;xmlns:xsi</span><span style="color: blue">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: red"><br />
&nbsp;&nbsp;&nbsp;&nbsp;xsi:schemaLocation</span><span style="color: blue">="http://www.springframework.org/schema/beans&nbsp;http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;</span><span style="color: black"><br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue">&lt;</span><span style="color: maroon">bean&nbsp;</span><span style="color: red">id</span><span style="color: blue">="display"</span><span style="color: red"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class</span><span style="color: blue">="com.duduli.li.Display"&gt;</span><span style="color: black"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue">&lt;/</span><span style="color: maroon">bean</span><span style="color: blue">&gt;</span><span style="color: black"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue">&lt;</span><span style="color: maroon">bean&nbsp;</span><span style="color: red">id</span><span style="color: blue">="atuoRun"</span><span style="color: red"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class</span><span style="color: blue">="com.duduli.li.AutoRan"&gt;</span><span style="color: black"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue">&lt;</span><span style="color: maroon">property&nbsp;</span><span style="color: red">name</span><span style="color: blue">="display"</span><span style="color: red">&nbsp;ref</span><span style="color: blue">="display"&gt;&lt;/</span><span style="color: maroon">property</span><span style="color: blue">&gt;</span><span style="color: black"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue">&lt;/</span><span style="color: maroon">bean</span><span style="color: blue">&gt;</span><span style="color: black"><br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue">&lt;</span><span style="color: maroon">bean&nbsp;</span><span style="color: red">id</span><span style="color: blue">="aR"</span><span style="color: red"><br />
&nbsp;&nbsp;&nbsp;&nbsp;class</span><span style="color: blue">="org.springframework.scheduling.timer.ScheduledTimerTask"&gt;</span><span style="color: black"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: blue">&lt;</span><span style="color: maroon">property&nbsp;</span><span style="color: red">name</span><span style="color: blue">="timerTask"</span><span style="color: red">&nbsp;ref</span><span style="color: blue">="atuoRun"&gt;&lt;/</span><span style="color: maroon">property</span><span style="color: blue">&gt;</span><span style="color: black"><br />
</span><span style="color: green">&lt;!--<br />
period</span></span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">多长时间运行一次，</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">delay</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">表示允许你当任务第一次运行前应该等待多久</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial"><br />
--&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">name</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="period"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;value</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="5000"&gt;&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">name</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="delay"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;value</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="2000"&gt;&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">id</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="test"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;class</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="org.springframework.scheduling.timer.TimerFactoryBean"&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">name</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="scheduledTimerTasks"&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">list</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&lt;!--<br />
</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">这里使用</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">list</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">，可以调度多个</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">bean</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">，</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial"><br />
--&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">ref&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">bean</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="aR"/&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">list</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">beans</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span></p>
<p style="background: white; vertical-align: top; line-height: 150%"><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial"><br />
</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">再来就是客户端调度了。</span></p>
<p style="background: #eeeeee; vertical-align: top; word-break: break-all; line-height: 150%"><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">package</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;com.duduli.li;<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">import</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;org.springframework.beans.factory.BeanFactory;<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">import</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;org.springframework.context.support.ClassPathXmlApplicationContext;<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">class</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;Client&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">static</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">void</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;main(String[]&nbsp;args)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BeanFactory&nbsp;factory&nbsp;=&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">new</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;ClassPathXmlApplicationContext("applicationContext.xml");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;factory.getBean("test");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</span></p>
<p style="background: white; vertical-align: top; line-height: 150%"><span style="font-family: Arial"><a href="http://www.blogjava.net/duduli/archive/2009/03/11/259026.html">spring<span style="font-family: SimSun">与自动调度任务</span>(<span style="font-family: SimSun">二</span>)</a> </span></p>
<p style="background: white; vertical-align: top; line-height: 150%"><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">使用</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">quartz</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">和</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">spring</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">自动调度。</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial"><br />
</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">具体实现</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">bean</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">：</span></p>
<p style="background: #eeeeee; vertical-align: top; word-break: break-all; line-height: 150%"><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">package</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;com.duduli.li.quartz;<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">import</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;java.util.Date;<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">class</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;Display&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;@SuppressWarnings("deprecation")<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">void</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;disp(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">new</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;Date().getSeconds());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: SimSun">自动控制测试</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">");<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</span></p>
<p style="background: white; vertical-align: top; line-height: 150%"><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">继承</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">quartzjobbean</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">类：这个类和继承</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">Timer</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">类类似</span><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial"><br />
</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">。</span></p>
<p style="background: #eeeeee; vertical-align: top; word-break: break-all; line-height: 150%"><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">package</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;com.duduli.li.quartz;<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">import</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;org.quartz.JobExecutionContext;<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">import</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;org.quartz.JobExecutionException;<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">import</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;org.springframework.scheduling.quartz.QuartzJobBean;<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">class</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;AutoRun&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">extends</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;QuartzJobBean{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">private</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;Display&nbsp;&nbsp;display;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">void</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;setDisplay(Display&nbsp;display)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">this</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">.display&nbsp;=&nbsp;display;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">protected</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">void</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;executeInternal(JobExecutionContext&nbsp;arg0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">throws</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;JobExecutionException&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.disp();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</span></p>
<p style="background: white; vertical-align: top; line-height: 150%"><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">spring</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">配置文件：</span></p>
<p style="background: #eeeeee; vertical-align: top; word-break: break-all; line-height: 150%"><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&lt;!--&nbsp;quartz</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">进行自动调度</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&nbsp;--&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&lt;!--&nbsp;</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">具体实现类</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&nbsp;--&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">id</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="display2"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;&nbsp;&nbsp;&nbsp;class</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="com.duduli.li.quartz.Display"&gt;&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&lt;!--&nbsp;spring</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">对</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">quartz</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">的支持，</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">Auto</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">类实现</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">quartz</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">的</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">job</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">接口的类，</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">jobDataAsMap</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">是将实现类注入其中</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&nbsp;--&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">id</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="quartz"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;class</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="org.springframework.scheduling.quartz.JobDetailBean"&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">name</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="jobClass"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;value</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="com.duduli.li.quartz.AutoRun"/&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">name</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="jobDataAsMap"&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">map</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">entry&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">key</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="display"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;value-ref</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="display2"&gt;&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">entry</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">map</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&lt;!--&nbsp;spring</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">对</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">quartz</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">的支持，对其值的设定</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&nbsp;--&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">id</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="simpleTask"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;class</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="org.springframework.scheduling.quartz.SimpleTriggerBean"&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">name</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="jobDetail"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;ref</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="quartz"&gt;&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">name</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="startDelay"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;value</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="2000"&gt;&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">name</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="repeatInterval"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;value</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="2000"&gt;&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&lt;!--&nbsp;</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: SimSun">启动自动调度</span><span style="font-size: 10pt; color: green; line-height: 150%; font-family: Arial">&nbsp;--&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">id</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="quartzTest"</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">&nbsp;class</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">name</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="triggers"&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">list</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">ref&nbsp;</span><span style="font-size: 10pt; color: red; line-height: 150%; font-family: Arial">bean</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">="simpleTask"/&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">list</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">property</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&lt;/</span><span style="font-size: 10pt; color: maroon; line-height: 150%; font-family: Arial">bean</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">&gt;</span></p>
<p style="background: white; vertical-align: top; line-height: 150%"><span style="font-size: 10.5pt; line-height: 150%; font-family: Arial">client</span><span style="font-size: 10.5pt; line-height: 150%; font-family: SimSun">调用：</span></p>
<p style="background: #eeeeee; vertical-align: top; word-break: break-all; line-height: 150%"><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">package</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;com.duduli.li.quartz;<br />
<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">import</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;org.springframework.beans.factory.BeanFactory;<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">import</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;org.springframework.context.support.ClassPathXmlApplicationContext;<br />
<br />
</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">class</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;Client&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">public</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">static</span>&nbsp;<span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">void</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;main(String[]&nbsp;args)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BeanFactory&nbsp;factory&nbsp;=&nbsp;</span><span style="font-size: 10pt; color: blue; line-height: 150%; font-family: Arial">new</span><span style="font-size: 10pt; color: black; line-height: 150%; font-family: Arial">&nbsp;ClassPathXmlApplicationContext("applicationContext.xml");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;factory.getBean("quartzTest");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</span></p>
<img src ="http://www.blogjava.net/SunRiver/aggbug/259312.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/SunRiver/" target="_blank">Sun River</a> 2009-03-12 12:42 <a href="http://www.blogjava.net/SunRiver/archive/2009/03/12/259312.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java Interthread communication </title><link>http://www.blogjava.net/SunRiver/archive/2009/03/12/259305.html</link><dc:creator>Sun River</dc:creator><author>Sun River</author><pubDate>Thu, 12 Mar 2009 04:09:00 GMT</pubDate><guid>http://www.blogjava.net/SunRiver/archive/2009/03/12/259305.html</guid><description><![CDATA[<p>Java implements a very efficient interprocess communication which reduces the CPU&#8217;s idle time to a very great extent. It is been implemented through wait ( ), notify ( ) and notifyAll ( ) methods. Since these methods are implemented as final methods they are present in all the classes. </p>
<p>The basic functionality of each one of them is as under: </p>
<p><br />
■ <strong>wait( )</strong> acts as a intimation to the calling thread to give up the monitor and go to sleep until some other thread enters the same monitor and calls notify( ). </p>
<p>■ <strong>notify( )</strong> is used as intimator to wake up the first thread that called wait( ) on the same object. </p>
<p>■ <strong>notifyAll( )</strong> as the term states wakes up all the threads that called wait( ) on the same object. The highest priority thread will run first. </p>
<p><br />
</p>
<pre class="java5"><span style="font-weight: bold; color: #000000">public</span> <span style="font-weight: bold; color: #000000">class</span> WaitNotifyAllExample <span style="color: #66cc66">{</span>
&nbsp;
<span style="font-weight: bold; color: #000000">public</span> <span style="font-weight: bold; color: #000000">static</span> <span style="color: #993333">void</span> main<span style="color: #66cc66">(</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span style="font-weight: bold; color: #aaaadd">String</span></a><span style="color: #66cc66">[</span><span style="color: #66cc66">]</span> args<span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span>
&nbsp;
<span style="font-weight: bold; color: #000000">try</span> <span style="color: #66cc66">{</span>
<a href="http://www.google.com/search?sitesearch=java.sun.com&amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+Object"><span style="font-weight: bold; color: #aaaadd">Object</span></a> o = <span style="font-weight: bold; color: #000000">new</span> <a href="http://www.google.com/search?sitesearch=java.sun.com&amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+Object"><span style="font-weight: bold; color: #aaaadd">Object</span></a><span style="color: #66cc66">(</span><span style="color: #66cc66">)</span>;
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html"><span style="font-weight: bold; color: #aaaadd">Thread</span></a> thread1 = <span style="font-weight: bold; color: #000000">new</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html"><span style="font-weight: bold; color: #aaaadd">Thread</span></a><span style="color: #66cc66">(</span><span style="font-weight: bold; color: #000000">new</span> MyOwnRunnable<span style="color: #66cc66">(</span><span style="color: #ff0000">"A"</span>, o<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>;
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html"><span style="font-weight: bold; color: #aaaadd">Thread</span></a> thread2 = <span style="font-weight: bold; color: #000000">new</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html"><span style="font-weight: bold; color: #aaaadd">Thread</span></a><span style="color: #66cc66">(</span><span style="font-weight: bold; color: #000000">new</span> MyOwnRunnable<span style="color: #66cc66">(</span><span style="color: #ff0000">"B"</span>, o<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>;
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html"><span style="font-weight: bold; color: #aaaadd">Thread</span></a> thread3 = <span style="font-weight: bold; color: #000000">new</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html"><span style="font-weight: bold; color: #aaaadd">Thread</span></a><span style="color: #66cc66">(</span><span style="font-weight: bold; color: #000000">new</span> MyOwnRunnable<span style="color: #66cc66">(</span><span style="color: #ff0000">"C"</span>, o<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>;
&nbsp;
<span style="color: #808080; font-style: italic">// synchronized keyword acquires lock on the object.</span>
<span style="font-weight: bold; color: #000000">synchronized</span> <span style="color: #66cc66">(</span>o<span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span>
thread1.<span style="color: #006600">start</span><span style="color: #66cc66">(</span><span style="color: #66cc66">)</span>;
<span style="color: #808080; font-style: italic">// wait till the first thread completes execution.</span>
<span style="color: #808080; font-style: italic">// thread should acquire the lock on the object</span>
<span style="color: #808080; font-style: italic">// before calling wait method on it. Otherwise it will</span>
<span style="color: #808080; font-style: italic">// throw java.lang.IllegalMonitorStateException </span>
o.<span style="color: #006600">wait</span><span style="color: #66cc66">(</span><span style="color: #66cc66">)</span>;
thread2.<span style="color: #006600">start</span><span style="color: #66cc66">(</span><span style="color: #66cc66">)</span>;
<span style="color: #808080; font-style: italic">// wait till the second thread completes execution</span>
o.<span style="color: #006600">wait</span><span style="color: #66cc66">(</span><span style="color: #66cc66">)</span>;
thread3.<span style="color: #006600">start</span><span style="color: #66cc66">(</span><span style="color: #66cc66">)</span>;
<span style="color: #66cc66">}</span>
&nbsp;
<span style="color: #66cc66">}</span>
<span style="font-weight: bold; color: #000000">catch</span> <span style="color: #66cc66">(</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/InterruptedException.html"><span style="font-weight: bold; color: #aaaadd">InterruptedException</span></a> e<span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span>
e.<span style="color: #006600">printStackTrace</span><span style="color: #66cc66">(</span><span style="color: #66cc66">)</span>;
<span style="color: #66cc66">}</span>
&nbsp;
<span style="color: #66cc66">}</span>
<span style="color: #66cc66">}</span>
&nbsp;
<span style="font-weight: bold; color: #000000">class</span> MyOwnRunnable <span style="font-weight: bold; color: #000000">implements</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runnable.html"><span style="font-weight: bold; color: #aaaadd">Runnable</span></a> <span style="color: #66cc66">{</span>
&nbsp;
<span style="font-weight: bold; color: #000000">private</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span style="font-weight: bold; color: #aaaadd">String</span></a> threadName;
&nbsp;
<span style="font-weight: bold; color: #000000">private</span> <a href="http://www.google.com/search?sitesearch=java.sun.com&amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+Object"><span style="font-weight: bold; color: #aaaadd">Object</span></a> o;
&nbsp;
<span style="font-weight: bold; color: #000000">public</span> MyOwnRunnable<span style="color: #66cc66">(</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span style="font-weight: bold; color: #aaaadd">String</span></a> name, <a href="http://www.google.com/search?sitesearch=java.sun.com&amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+Object"><span style="font-weight: bold; color: #aaaadd">Object</span></a> o<span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span>
threadName = name;
<span style="font-weight: bold; color: #000000">this</span>.<span style="color: #006600">o</span> = o;
<span style="color: #66cc66">}</span>
&nbsp;
<span style="font-weight: bold; color: #000000">public</span> <span style="color: #993333">void</span> run<span style="color: #66cc66">(</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span>
&nbsp;
&nbsp;
<span style="font-weight: bold; color: #000000">synchronized</span> <span style="color: #66cc66">(</span>o<span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span>
<span style="color: #b1b100">for</span> <span style="color: #66cc66">(</span><span style="color: #993333">int</span> i = <span style="color: #cc66cc">0</span>; i &lt; <span style="color: #cc66cc">1000</span>; i++<span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span>
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"><span style="font-weight: bold; color: #aaaadd">System</span></a>.<span style="color: #006600">out</span>.<span style="color: #006600">println</span><span style="color: #66cc66">(</span><span style="color: #ff0000">"Thread "</span> + threadName + <span style="color: #ff0000">" Count&nbsp;: "</span> + i<span style="color: #66cc66">)</span>;
<span style="color: #66cc66">}</span>
<span style="color: #808080; font-style: italic">// notify all threads waiting for the object o.</span>
<span style="color: #808080; font-style: italic">// thread should acquire the lock on the object</span>
<span style="color: #808080; font-style: italic">// before calling notify or notifyAll method on it. </span>
<span style="color: #808080; font-style: italic">// Otherwise it will throw java.lang.IllegalMonitorStateException </span>
o.<span style="color: #006600">notifyAll</span><span style="color: #66cc66">(</span><span style="color: #66cc66">)</span>;
<span style="color: #66cc66">}</span>
<span style="color: #66cc66">}</span>
<span style="color: #66cc66">}</span></pre>
<img src ="http://www.blogjava.net/SunRiver/aggbug/259305.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/SunRiver/" target="_blank">Sun River</a> 2009-03-12 12:09 <a href="http://www.blogjava.net/SunRiver/archive/2009/03/12/259305.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Creating Array Objects in JavaScript with JSON</title><link>http://www.blogjava.net/SunRiver/archive/2009/03/10/258758.html</link><dc:creator>Sun River</dc:creator><author>Sun River</author><pubDate>Tue, 10 Mar 2009 03:42:00 GMT</pubDate><guid>http://www.blogjava.net/SunRiver/archive/2009/03/10/258758.html</guid><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;只有注册用户登录后才能阅读该文。<a href='http://www.blogjava.net/SunRiver/archive/2009/03/10/258758.html'>阅读全文</a><img src ="http://www.blogjava.net/SunRiver/aggbug/258758.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/SunRiver/" target="_blank">Sun River</a> 2009-03-10 11:42 <a href="http://www.blogjava.net/SunRiver/archive/2009/03/10/258758.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>