﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-丄諦啲仇魜ヤ              -文章分类-JAVA基础</title><link>http://www.blogjava.net/Crying/category/27216.html</link><description>如 果 敌 人 让 你 生 气 , 那 说 明 你 没 有 胜 他 的 把 握！ 
</description><language>zh-cn</language><lastBuildDate>Thu, 22 May 2008 18:43:55 GMT</lastBuildDate><pubDate>Thu, 22 May 2008 18:43:55 GMT</pubDate><ttl>60</ttl><item><title>利用servlet监听器实现jsp中在线人数统计的方法</title><link>http://www.blogjava.net/Crying/articles/195587.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Thu, 24 Apr 2008 07:01:00 GMT</pubDate><guid>http://www.blogjava.net/Crying/articles/195587.html</guid><wfw:comment>http://www.blogjava.net/Crying/comments/195587.html</wfw:comment><comments>http://www.blogjava.net/Crying/articles/195587.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Crying/comments/commentRss/195587.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Crying/services/trackbacks/195587.html</trackback:ping><description><![CDATA[<div style="font-size: 10.5pt;">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 20pt; line-height: 16.5pt;"><span style="font-size: 10pt;"><font face="宋体">在网站中经常需要进行在线人数的统计。过去的一般做法是结合登录和退出功能，即当用户输入用户名密码进行登录的时候计数器加</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">1</span><span style="font-size: 10pt;"><font face="宋体">，然后当用户点击退出按钮退出系统的时候计数器减</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">1</span><span style="font-size: 10pt;"><font face="宋体">。这种处理方式存在一些缺点，例如：用户正常登录后，可能会忘记点击退出按钮，而直接关闭浏览器，导致计数器减</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">1</span><span style="font-size: 10pt;"><font face="宋体">的操作没有及时执行；网站上还经常有一些内容是不需要登录就可以访问的，在这种情况下也无法使用上面的方法进行在线人数统计。</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><br />
</span><span style="font-size: 10pt;"><font face="宋体">　　我们可以利用</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">Servlet</span><span style="font-size: 10pt;"><font face="宋体">规范中定义的事件监听器（</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">Listener</span><span style="font-size: 10pt;"><font face="宋体">）来解决这个问题，实现更准确的在线人数统计功能。对每一个正在访问的用户，</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">J2EE</span><span style="font-size: 10pt;"><font face="宋体">应用服务器会为其建立一个对应的</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSession</span><span style="font-size: 10pt;"><font face="宋体">对象。当一个浏览器第一次访问网站的时候，</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">J2EE</span><span style="font-size: 10pt;"><font face="宋体">应用服务器会新建一个</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSession</span><span style="font-size: 10pt;"><font face="宋体">对象，并触发</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSession</span><span style="font-size: 10pt;"><font face="宋体">创建事件，如果注册了</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSessionListener</span><span style="font-size: 10pt;"><font face="宋体">事件监听器，则会调用</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSessionListener</span><span style="font-size: 10pt;"><font face="宋体">事件监听器的</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">sessionCreated</span><span style="font-size: 10pt;"><font face="宋体">方法。相反，当这个浏览器访问结束超时的时候，</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">J2EE</span><span style="font-size: 10pt;"><font face="宋体">应用服务器会销毁相应的</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSession</span><span style="font-size: 10pt;"><font face="宋体">对象，触发</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSession</span><span style="font-size: 10pt;"><font face="宋体">销毁事件，同时调用所注册</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSessionListener</span><span style="font-size: 10pt;"><font face="宋体">事件监听器的</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">sessionDestroyed</span><span style="font-size: 10pt;"><font face="宋体">方法。</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><br />
</span><span style="font-size: 10pt;"><font face="宋体">　　可见，对应于一个用户访问的开始和结束，相应的有</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">sessionCreated</span><span style="font-size: 10pt;"><font face="宋体">方法和</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">sessionDestroyed</span><span style="font-size: 10pt;"><font face="宋体">方法执行。这样，我们只需要在</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSessionListener</span><span style="font-size: 10pt;"><font face="宋体">实现类的</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">sessionCreated</span><span style="font-size: 10pt;"><font face="宋体">方法中让计数器加</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">1</span><span style="font-size: 10pt;"><font face="宋体">，在</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">sessionDestroyed</span><span style="font-size: 10pt;"><font face="宋体">方法中让计数器减</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">1</span><span style="font-size: 10pt;"><font face="宋体">，就轻松实现了网站在线人数的统计功能。</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><br />
</span><span style="font-size: 10pt;"><font face="宋体">　　下面就是利用</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSessionListener</span><span style="font-size: 10pt;"><font face="宋体">实现在线人数统计的一个例子，这个例子已经在中创软件的</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">J2EE</span><span style="font-size: 10pt;"><font face="宋体">应用服务器</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">InforWeb</span><span style="font-size: 10pt;"><font face="宋体">中测试通过。</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><br />
</span><font face="宋体"><span style="font-size: 10pt;">　　首先，编写一个简单的计数器，代码如下：</span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><O:P></O:P></span></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">1.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">package</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;accp.onlinecounter;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">2.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">public</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">class</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;OnlineCounter&nbsp;{
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">3.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">private</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">static</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">long</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;online&nbsp;=&nbsp;0;&nbsp;&nbsp;&nbsp;&nbsp;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">4.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">public</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">static</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">long</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;getOnline()&nbsp;{
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">5.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">return</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;online;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">6.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp; <O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">7.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">public</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">static</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">void</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;raise(){
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">8.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;online++;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">9.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp; <O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">10.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">public</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">static</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">void</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;reduce(){
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">11.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;online--;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">12.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;}
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">13.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">}
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; line-height: 16.5pt;"><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><br />
</span><span style="font-size: 10pt;"><font face="宋体">　　然后，编写</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSessionListener</span><span style="font-size: 10pt;"><font face="宋体">实现类，在这个实现类的</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">sessionCreated</span><span style="font-size: 10pt;"><font face="宋体">方法中调用</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">OnlineCounter</span><span style="font-size: 10pt;"><font face="宋体">的</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">raise</span><span style="font-size: 10pt;"><font face="宋体">方法，在</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">sessionDestroyed</span><span style="font-size: 10pt;"><font face="宋体">方法中调用</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">OnlineCounter</span><span style="font-size: 10pt;"><font face="宋体">的</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">reduce</span><font face="宋体"><span style="font-size: 10pt;">方法，代码如下：</span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><O:P></O:P></span></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">1.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">package</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;accp.onlinecounter;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">2.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">import</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;javax.servlet.http.<a href="http://www.javaresearch.org:88/source/j2ee1.3.1/javax/servlet/http/HttpSessionEvent.java.html" target="_blank"><u><span style="color: red;">HttpSessionEvent</span></u></a>;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">3.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">import</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;javax.servlet.http.<a href="http://www.javaresearch.org:88/source/j2ee1.3.1/javax/servlet/http/HttpSessionListener.java.html" target="_blank"><u><span style="color: red;">HttpSessionListener</span></u></a>;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">4.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">public</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">class</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;OnlineCounterListener&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">implements</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;<a href="http://www.javaresearch.org:88/source/j2ee1.3.1/javax/servlet/http/HttpSessionListener.java.html" target="_blank"><u><span style="color: red;">HttpSessionListener</span></u></a>&nbsp;{
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">5.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">public</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">void</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;sessionCreated(<a href="http://www.javaresearch.org:88/source/j2ee1.3.1/javax/servlet/http/HttpSessionEvent.java.html" target="_blank"><u><span style="color: red;">HttpSessionEvent</span></u></a>&nbsp;hse)&nbsp;{
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">6.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OnlineCounter.raise();
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">7.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;}
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">8.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">public</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">void</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;sessionDestroyed(<a href="http://www.javaresearch.org:88/source/j2ee1.3.1/javax/servlet/http/HttpSessionEvent.java.html" target="_blank"><u><span style="color: red;">HttpSessionEvent</span></u></a>&nbsp;hse)&nbsp;{
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">9.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OnlineCounter.reduce();
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">10.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;}
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">11.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">}
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; line-height: 16.5pt;"><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><br />
</span><span style="font-size: 10pt;"><font face="宋体">　　再然后，把这个</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">HttpSessionListener</span><span style="font-size: 10pt;"><font face="宋体">实现类注册到网站应用中，也就是在网站应用的</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">web.xml</span><font face="宋体"><span style="font-size: 10pt;">中加入如下内容：</span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><O:P></O:P></span></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">1.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&lt;web-app&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">2.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&#8230;&#8230; <O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">3.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&lt;listener&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">4.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;listener-</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">class</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">5.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;accp.OnlineCounterListener
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">6.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/listener-</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">class</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">7.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/listener&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">8.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&#8230;&#8230; <O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">9.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&lt;/web-app&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; line-height: 16.5pt;"><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><br />
</span><span style="font-size: 10pt;"><font face="宋体">　　</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">OK</span><span style="font-size: 10pt;"><font face="宋体">，在线人数统计功能已经实现，只要在</font></span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US">JSP</span><font face="宋体"><span style="font-size: 10pt;">页面中加入下面这样的脚本就能显示但前在线人数了：</span><span style="font-size: 10pt; font-family: Arial;" lang="EN-US"><O:P></O:P></span></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">1.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&lt;%@&nbsp;page&nbsp;language=</span><span style="font-size: 14pt; color: #ff33ff; font-family: Arial;" lang="EN-US">"java"</span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;pageEncoding=</span><span style="font-size: 14pt; color: #ff33ff; font-family: Arial;" lang="EN-US">"GB2312"</span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;%&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">2.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&lt;%@&nbsp;page&nbsp;</span><strong><span style="font-size: 14pt; color: blue; font-family: Arial;" lang="EN-US">import</span></strong><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">=</span><span style="font-size: 14pt; color: #ff33ff; font-family: Arial;" lang="EN-US">"accp.OnlineCounter"</span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;%&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">3.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&lt;html&gt; <O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">4.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;&lt;title&gt;On&nbsp;Line&nbsp;Counert&lt;/title&gt;&lt;/head&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">5.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&nbsp;bgcolor=</span><span style="font-size: 14pt; color: #ff33ff; font-family: Arial;" lang="EN-US">"#FFFFFF"</span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">6.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;On&nbsp;line:&lt;%=OnlineCounter.getOnline()%&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">7.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;
<O:P></O:P></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 36pt; background: white none repeat scroll 0% 50%; text-indent: -18pt; line-height: 16.5pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">8.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span><span style="font-size: 14pt; font-family: Arial;" lang="EN-US">&lt;/html&gt;
<O:P></O:P></span></p>
</div>
<img src ="http://www.blogjava.net/Crying/aggbug/195587.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Crying/" target="_blank">Crying</a> 2008-04-24 15:01 <a href="http://www.blogjava.net/Crying/articles/195587.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>利用监听器 定时执行 （ServletContexListener）</title><link>http://www.blogjava.net/Crying/articles/186636.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Sun, 16 Mar 2008 10:20:00 GMT</pubDate><guid>http://www.blogjava.net/Crying/articles/186636.html</guid><wfw:comment>http://www.blogjava.net/Crying/comments/186636.html</wfw:comment><comments>http://www.blogjava.net/Crying/articles/186636.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Crying/comments/commentRss/186636.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Crying/services/trackbacks/186636.html</trackback:ping><description><![CDATA[<p>Timer一种工具，线程用其安排以后在后台线程中执行的任务。可安排任务执行一次，或者定期重复执行。
<p>与每个 <tt>Timer</tt> 对象相对应的是单个后台线程，用于顺序地执行所有计时器任务。计时器任务应该迅速完成。如果完成某个计时器任务的时间太长，那么它会&#8220;独占&#8221;计时器的任务执行线程。因此，这就可能延迟后续任务的执行，而这些任务就可能&#8220;堆在一起&#8221;，并且在上述不友好的任务最终完成时才能够被快速连续地执行。
<p>对 <tt>Timer</tt> 对象最后的引用完成后，<em>并且</em> 所有未处理的任务都已执行完成后，计时器的任务执行线程会正常终止（并且成为垃圾回收的对象）。但是这可能要很长时间后才发生。默认情况下，任务执行线程并不作为<em>守护线程</em> 来运行，所以它能够阻止应用程序终止。如果调用者想要快速终止计时器的任务执行线程，那么调用者应该调用计时器的 <tt>cancel</tt> 方法。
<p>如果意外终止了计时器的任务执行线程，例如调用了它的 <tt>stop</tt> 方法，那么所有以后对该计时器安排任务的尝试都将导致 <tt>IllegalStateException</tt>，就好像调用了计时器的 <tt>cancel</tt> 方法一样。
<p>此类是线程安全的：多个线程可以共享单个 <tt>Timer</tt> 对象而无需进行外部同步。
<p>此类<em>不</em> 提供实时保证：它使用 <tt>Object.wait(long)</tt> 方法来安排任务。
<p>实现注意事项：此类可扩展到大量同时安排的任务（存在数千个都没有问题）。在内部，它使用二进制堆来表示其任务队列，所以安排任务的开销是 O(log n)，其中 n 是同时安排的任务数。
<p>实现注意事项：所有构造方法都启动计时器线程</p>
<p><br />
import java.util.Timer;<br />
import javax.servlet.ServletContextEvent;<br />
import javax.servlet.ServletContextListener;</p>
<p>public class MyListner implements ServletContextListener {<br />
&nbsp;&nbsp;&nbsp; private Timer timer=null;<br />
&nbsp;&nbsp;&nbsp; private long start=0;<br />
&nbsp;&nbsp;&nbsp; private long end=1000*60;</p>
<p>&nbsp;public void contextInitialized(ServletContextEvent event1) {<br />
&nbsp;&nbsp;&nbsp; &nbsp;timer=new Timer(true);<br />
&nbsp;&nbsp;&nbsp;&nbsp; timer.schedule(new Str(),start,end);<br />
<table cellspacing="0" cellpadding="3" width="100%" summary="" border="1">
    <tbody>
        <tr class="TableRowColor" bgcolor="white">
            <td valign="top" align="right" width="1%"><font size="-1"><code>void</code></font></td>
            <td><code><strong><a href="mk:@MSITStore:C:\Documents%20and%20Settings\a\桌面\JDK_API_1_6_zh_CN.CHM::/java/util/Timer.html#schedule(java.util.TimerTask, java.util.Date)">schedule</a></strong>(<a title="java.util 中的类" href="mk:@MSITStore:C:\Documents%20and%20Settings\a\桌面\JDK_API_1_6_zh_CN.CHM::/java/util/TimerTask.html">TimerTask</a>&nbsp;task, <a title="java.util 中的类" href="mk:@MSITStore:C:\Documents%20and%20Settings\a\桌面\JDK_API_1_6_zh_CN.CHM::/java/util/Date.html">Date</a>&nbsp;time)</code> <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安排在指定的时间执行指定的任务。</td>
        </tr>
        <tr class="TableRowColor" bgcolor="white">
            <td valign="top" align="right" width="1%"><font size="-1"><code>&nbsp;void</code></font></td>
            <td><code><strong><a href="mk:@MSITStore:C:\Documents%20and%20Settings\a\桌面\JDK_API_1_6_zh_CN.CHM::/java/util/Timer.html#schedule(java.util.TimerTask, java.util.Date, long)">schedule</a></strong>(<a title="java.util 中的类" href="mk:@MSITStore:C:\Documents%20and%20Settings\a\桌面\JDK_API_1_6_zh_CN.CHM::/java/util/TimerTask.html">TimerTask</a>&nbsp;task, <a title="java.util 中的类" href="mk:@MSITStore:C:\Documents%20and%20Settings\a\桌面\JDK_API_1_6_zh_CN.CHM::/java/util/Date.html">Date</a>&nbsp;firstTime, long&nbsp;period)</code> <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安排指定的任务在指定的时间开始进行重复的<em>固定延迟执行</em>。</td>
        </tr>
        <tr class="TableRowColor" bgcolor="white">
            <td valign="top" align="right" width="1%"><font size="-1"><code>&nbsp;void</code></font></td>
            <td><code><strong><a href="mk:@MSITStore:C:\Documents%20and%20Settings\a\桌面\JDK_API_1_6_zh_CN.CHM::/java/util/Timer.html#schedule(java.util.TimerTask, long)">schedule</a></strong>(<a title="java.util 中的类" href="mk:@MSITStore:C:\Documents%20and%20Settings\a\桌面\JDK_API_1_6_zh_CN.CHM::/java/util/TimerTask.html">TimerTask</a>&nbsp;task, long&nbsp;delay)</code> <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安排在指定延迟后执行指定的任务。</td>
        </tr>
        <tr class="TableRowColor" bgcolor="white">
            <td valign="top" align="right" width="1%"><font size="-1"><code>&nbsp;void</code></font></td>
            <td><code><strong><a href="mk:@MSITStore:C:\Documents%20and%20Settings\a\桌面\JDK_API_1_6_zh_CN.CHM::/java/util/Timer.html#schedule(java.util.TimerTask, long, long)">schedule</a></strong>(<a title="java.util 中的类" href="mk:@MSITStore:C:\Documents%20and%20Settings\a\桌面\JDK_API_1_6_zh_CN.CHM::/java/util/TimerTask.html">TimerTask</a>&nbsp;task, long&nbsp;delay, long&nbsp;period)</code> <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安排指定的任务从指定的延迟后开始进行重复的<em>固定延迟执行</em></td>
        </tr>
    </tbody>
</table>
<br />
&nbsp;}<br />
&nbsp;public void contextDestroyed(ServletContextEvent event0)&nbsp; {<br />
&nbsp;&nbsp;timer.cancel();//&nbsp;终止此计时器，丢弃所有当前已安排的任务。<br />
&nbsp;}</p>
<p>}<br />
</p>
<p>import java.util.Date;<br />
import java.util.TimerTask;</p>
<p>public class Str extends TimerTask{<br />
<br />
&nbsp;public void run() {<br />
&nbsp;&nbsp;&nbsp; System.out.println("定时测试成功！"+(new Date()));<br />
}<br />
}<br />
<br />
web.xml加以配置</p>
<p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;web-app version="2.5" <br />
&nbsp;xmlns="http://java.sun.com/xml/ns/javaee" <br />
&nbsp;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <br />
&nbsp;xsi:schemaLocation="http://java.sun.com/xml/ns/javaee <br />
&nbsp;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;<br />
&nbsp;&lt;listener&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;listener-class&gt; MyListner&lt;/listener-class&gt;&nbsp;<br />
&nbsp;&lt;/listener&gt;<br />
<br />
<br />
------------------------------------------------------------------------------------------------------------<br />
<br />
</p>
<p style="margin-left: 21pt"><a href="http://blog.csdn.net/feifniao/archive/2007/11/22/1897392.aspx">原文出处：<br />
http://blog.csdn.net/feifniao/archive/2007/11/22/1897392.aspx</a></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: 宋体">首先，如果你在</span><span style="font-size: 10pt; font-family: Verdana">web.xml</span><span style="font-size: 10pt; font-family: 宋体">文件中的配置是这样的：</span></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: Verdana">&nbsp;&nbsp;&lt;context-param&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&lt;param-value&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /WEB-INF/classes/applicationContext-*.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/param-value&gt;<br />
&nbsp;&lt;/context-param&gt;</span></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: 宋体">那么需要在工程下创建一个以</span><span style="font-size: 10pt; font-family: Verdana">applicationContext- </span><span style="font-size: 10pt; font-family: 宋体">为开头的</span><span style="font-size: 10pt; font-family: Verdana">xml</span><span style="font-size: 10pt; font-family: 宋体">文件</span><span style="font-size: 10pt; font-family: Verdana">eg:applicationContext-jobconfig.xml</span></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: Verdana">xml</span><span style="font-size: 10pt; font-family: 宋体">的头和结尾部分跟其他</span><span style="font-size: 10pt; font-family: Verdana">spring</span><span style="font-size: 10pt; font-family: 宋体">配置文件相似，就不赘述，正文如下：</span></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: Verdana">&nbsp;&lt;bean id="youJobName(</span><span style="font-size: 10pt; font-family: 宋体">类别名</span><span style="font-size: 10pt; font-family: Verdana">)" class="com.******.YourJobClassLocation(</span><span style="font-size: 10pt; font-family: 宋体">类的定位</span><span style="font-size: 10pt; font-family: Verdana">)" /&gt;<br />
&nbsp;&lt;bean id="doYourJob(</span><span style="font-size: 10pt; font-family: 宋体">别名</span><span style="font-size: 10pt; font-family: Verdana">)" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="targetObject"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&lt;ref bean="youJobName(</span><span style="font-size: 10pt; font-family: 宋体">类别名</span><span style="font-size: 10pt; font-family: Verdana">)""/&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/property&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="targetMethod"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&lt;value&gt;runMethodName(</span><span style="font-size: 10pt; font-family: 宋体">定时执行的方法名</span><span style="font-size: 10pt; font-family: Verdana">)&lt;/value&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/property&gt; <br />
&nbsp;&lt;/bean&gt;<br />
&nbsp;<br />
&nbsp;&lt;bean id="youJobNameTrigger(</span><span style="font-size: 10pt; font-family: 宋体">触发器别名</span><span style="font-size: 10pt; font-family: Verdana">)" class="org.springframework.scheduling.quartz.CronTriggerBean"&gt;<br />
&nbsp;&nbsp; &lt;property name="jobDetail"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;ref bean="doYourJob(</span><span style="font-size: 10pt; font-family: 宋体">别名</span><span style="font-size: 10pt; font-family: Verdana">)""/&gt;<br />
&nbsp;&nbsp; &lt;/property&gt;<br />
&nbsp;&nbsp; &lt;property name="cronExpression"&gt;<br />
&nbsp;&nbsp; &nbsp;&lt;value&gt;0 0/20 * * * ?(</span><span style="font-size: 10pt; color: red; font-family: 宋体">定时的时间配置</span><span style="font-size: 10pt; font-family: Verdana">)&lt;/value&gt;<br />
&nbsp;&nbsp; &lt;/property&gt;<br />
&nbsp;&lt;/bean&gt;</span></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: Verdana">&nbsp;&lt;bean id="doScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;<br />
&nbsp;&nbsp; &lt;property name="triggers"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;list&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&lt;ref local="youJobNameTrigger(</span><span style="font-size: 10pt; font-family: 宋体">触发器别名</span><span style="font-size: 10pt; font-family: Verdana">)"/&gt;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/list&gt;<br />
&nbsp;&nbsp; &lt;/property&gt;<br />
&nbsp;&lt;/bean&gt;</span></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: 宋体">这样的配置几本就可以运转了，但是有一个地方可能是你需要根据你的需求来确定的，那就是触发时间。</span></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: 宋体">下面有一些关于时间配置的说明：</span></p>
<p>
<table cellspacing="8" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><strong><span style="font-size: 11pt; font-family: 宋体">字段顺序</span></strong></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><strong>&nbsp;</strong></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><strong><span style="font-size: 11pt; font-family: 宋体">允许值</span></strong></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><strong>&nbsp;</strong></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><strong><span style="font-size: 11pt; font-family: 宋体">允许的特殊字符</span></strong></p>
            </td>
        </tr>
        <tr>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">秒</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">0-59</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">, - * /</span></p>
            </td>
        </tr>
        <tr>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">分</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">0-59</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">, - * /</span></p>
            </td>
        </tr>
        <tr>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">小时</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">0-23</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">, - * /</span></p>
            </td>
        </tr>
        <tr>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">日期</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">1-31</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">, - * ? / L W C</span></p>
            </td>
        </tr>
        <tr>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">月份</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">1-12&nbsp;</span><span style="font-family: 宋体">或者 JAN-DEC</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">, - * /</span></p>
            </td>
        </tr>
        <tr>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">星期</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">1-7&nbsp;</span><span style="font-family: 宋体">或者 SUN-SAT</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">, - * ? / L C #</span></p>
            </td>
        </tr>
        <tr>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">年（可选）</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">留空, 1970-2099</span></p>
            </td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt"></td>
            <td style="padding-right: 0.75pt; padding-left: 0.75pt; padding-bottom: 0.75pt; padding-top: 0.75pt">
            <p style="text-align: left" align="left"><span style="font-family: 宋体">, - * /</span></p>
            </td>
        </tr>
    </tbody>
</table>
</p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: Verdana"><br />
The '*' character is used to specify all values. For example, "*" in the minute field means "every minute". <br />
&#8220;*&#8221;</span><span style="font-size: 10pt; font-family: 宋体">字符被用来指定所有的值。如：</span><span style="font-size: 10pt; font-family: Verdana">&#8221;*&#8220;</span><span style="font-size: 10pt; font-family: 宋体">在分钟的字段域里表示</span><span style="font-size: 10pt; font-family: Verdana">&#8220;</span><span style="font-size: 10pt; font-family: 宋体">每分钟</span><span style="font-size: 10pt; font-family: Verdana">&#8221;</span><span style="font-size: 10pt; font-family: 宋体">。</span><span style="font-size: 10pt; font-family: Verdana"> <br />
The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify 'no specific value'. This is useful when you need to specify something in one of the two fileds, but not the other. See the examples below for clarification. <br />
&#8220;?&#8221;</span><span style="font-size: 10pt; font-family: 宋体">字符只在日期域和星期域中使用。它被用来指定</span><span style="font-size: 10pt; font-family: Verdana">&#8220;</span><span style="font-size: 10pt; font-family: 宋体">非明确的值</span><span style="font-size: 10pt; font-family: Verdana">&#8221;</span><span style="font-size: 10pt; font-family: 宋体">。当你需要通过在这两个域中的一个来指定一些东西的时候，它是有用的。看下面的例子你就会明白。</span><span style="font-size: 10pt; font-family: Verdana"> <br />
</span><span style="font-size: 10pt; font-family: 宋体">月份中的日期和星期中的日期这两个元素时互斥的一起应该通过设置一个问号</span><span style="font-size: 10pt; font-family: Verdana">(?)</span><span style="font-size: 10pt; font-family: 宋体">来表明不想设置那个字段</span><span style="font-size: 10pt; font-family: Verdana"><br />
<br />
The '-' character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12". <br />
&#8220;-&#8221;</span><span style="font-size: 10pt; font-family: 宋体">字符被用来指定一个范围。如：</span><span style="font-size: 10pt; font-family: Verdana">&#8220;10-12&#8221;</span><span style="font-size: 10pt; font-family: 宋体">在小时域意味着</span><span style="font-size: 10pt; font-family: Verdana">&#8220;10</span><span style="font-size: 10pt; font-family: 宋体">点、</span><span style="font-size: 10pt; font-family: Verdana">11</span><span style="font-size: 10pt; font-family: 宋体">点、</span><span style="font-size: 10pt; font-family: Verdana">12</span><span style="font-size: 10pt; font-family: 宋体">点</span><span style="font-size: 10pt; font-family: Verdana">&#8221;</span><span style="font-size: 10pt; font-family: 宋体">。</span><span style="font-size: 10pt; font-family: Verdana"> <br />
<br />
The ',' character is used to specify additional values. For example "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday". <br />
&#8220;,&#8221;</span><span style="font-size: 10pt; font-family: 宋体">字符被用来指定另外的值。如：</span><span style="font-size: 10pt; font-family: Verdana">&#8220;MON,WED,FRI&#8221;</span><span style="font-size: 10pt; font-family: 宋体">在星期域里表示</span><span style="font-size: 10pt; font-family: Verdana">&#8221;</span><span style="font-size: 10pt; font-family: 宋体">星期一、星期三、星期五</span><span style="font-size: 10pt; font-family: Verdana">&#8221;. <br />
<br />
The '/' character is used to specify increments. For example "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". Specifying '*' before the '/' is equivalent to specifying 0 is the value to start with. Essentially, for each field in the expression, there is a set of numbers that can be turned on or off. For seconds and minutes, the numbers range from 0 to 59. For hours 0 to 23, for days of the month 0 to 31, and for months 1 to 12. The "/" character simply helps you turn on every "nth" value in the given set. Thus "7/6" in the month field only turns on month "7", it does NOT mean every 6th month, please note that subtlety. </span></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: Verdana">"/"</span><span style="font-size: 10pt; font-family: 宋体">字符用来指定渐增的值。例如</span><span style="font-size: 10pt; font-family: Verdana">0/15</span><span style="font-size: 10pt; font-family: 宋体">出现在秒字段的时候意味着</span><span style="font-size: 10pt; font-family: Verdana">&#8220;</span><span style="font-size: 10pt; font-family: 宋体">在第</span><span style="font-size: 10pt; font-family: Verdana">0</span><span style="font-size: 10pt; font-family: 宋体">，</span><span style="font-size: 10pt; font-family: Verdana">15</span><span style="font-size: 10pt; font-family: 宋体">，</span><span style="font-size: 10pt; font-family: Verdana">30</span><span style="font-size: 10pt; font-family: 宋体">和</span><span style="font-size: 10pt; font-family: Verdana">45</span><span style="font-size: 10pt; font-family: 宋体">秒</span><span style="font-size: 10pt; font-family: Verdana">&#8221;</span><span style="font-size: 10pt; font-family: 宋体">（的时候被触发）。而</span><span style="font-size: 10pt; font-family: Verdana">5/15</span><span style="font-size: 10pt; font-family: 宋体">出现在秒字段的时候意味着</span><span style="font-size: 10pt; font-family: Verdana">&#8220;</span><span style="font-size: 10pt; font-family: 宋体">在第</span><span style="font-size: 10pt; font-family: Verdana">5</span><span style="font-size: 10pt; font-family: 宋体">，</span><span style="font-size: 10pt; font-family: Verdana">20</span><span style="font-size: 10pt; font-family: 宋体">，</span><span style="font-size: 10pt; font-family: Verdana">35</span><span style="font-size: 10pt; font-family: 宋体">和第</span><span style="font-size: 10pt; font-family: Verdana">50</span><span style="font-size: 10pt; font-family: 宋体">秒</span><span style="font-size: 10pt; font-family: Verdana">&#8221;</span><span style="font-size: 10pt; font-family: 宋体">（的时候被触发）。</span><span style="font-size: 10pt; font-family: Verdana">"*/"</span><span style="font-size: 10pt; font-family: 宋体">和</span><span style="font-size: 10pt; font-family: Verdana">"0/"</span><span style="font-size: 10pt; font-family: 宋体">的指定是等价的。</span></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: 宋体">注：当分子</span><span style="font-size: 10pt; font-family: Verdana">+</span><span style="font-size: 10pt; font-family: 宋体">分母的值大于该字段的最大值，如在秒钟字段出现</span><span style="font-size: 10pt; font-family: Verdana">45/20</span><span style="font-size: 10pt; font-family: 宋体">的时候，表示在第</span><span style="font-size: 10pt; font-family: Verdana">45</span><span style="font-size: 10pt; font-family: 宋体">秒以后的每</span><span style="font-size: 10pt; font-family: Verdana">20</span><span style="font-size: 10pt; font-family: 宋体">会触发一次，但是</span><span style="font-size: 10pt; font-family: Verdana">20</span><span style="font-size: 10pt; font-family: 宋体">秒以后又算做另外的时间段以内了，所以该字段的</span><span style="font-size: 10pt; font-family: Verdana">/20</span><span style="font-size: 10pt; font-family: 宋体">即失效，如改为</span><span style="font-size: 10pt; font-family: Verdana">45/10 </span><span style="font-size: 10pt; font-family: 宋体">则只有</span><span style="font-size: 10pt; font-family: 宋体">第</span><span style="font-size: 10pt; font-family: Verdana">45 </span><span style="font-size: 10pt; font-family: 宋体">和</span><span style="font-size: 10pt; font-family: Verdana">55</span><span style="font-size: 10pt; font-family: 宋体">秒会执行一次。</span><span style="font-size: 10pt; font-family: Verdana"><br />
<br />
The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results. <br />
<br />
L</span><span style="font-size: 10pt; font-family: 宋体">是</span><span style="font-size: 10pt; font-family: Verdana">&#8216;last&#8217;</span><span style="font-size: 10pt; font-family: 宋体">的省略写法可以表示</span><span style="font-size: 10pt; font-family: Verdana">day-of-month</span><span style="font-size: 10pt; font-family: 宋体">和</span><span style="font-size: 10pt; font-family: Verdana">day-of-week</span><span style="font-size: 10pt; font-family: 宋体">域，但在两个字段中的意思不同，例如</span><span style="font-size: 10pt; font-family: Verdana">day-of-month</span><span style="font-size: 10pt; font-family: 宋体">域中表示一个月的最后一天，</span><span style="font-size: 10pt; font-family: Verdana"><br />
</span><span style="font-size: 10pt; font-family: 宋体">如果在</span><span style="font-size: 10pt; font-family: Verdana">day-of-week</span><span style="font-size: 10pt; font-family: 宋体">域表示</span><span style="font-size: 10pt; font-family: Verdana">&#8216;7&#8217;</span><span style="font-size: 10pt; font-family: 宋体">或者</span><span style="font-size: 10pt; font-family: Verdana">&#8216;SAT&#8217;</span><span style="font-size: 10pt; font-family: 宋体">，如果在</span><span style="font-size: 10pt; font-family: Verdana">day-of-week</span><span style="font-size: 10pt; font-family: 宋体">域中前面加上数字，它表示一个月的最后几天，例如</span><span style="font-size: 10pt; font-family: Verdana">&#8216;6L&#8217;</span><span style="font-size: 10pt; font-family: 宋体">就表示一个月的最后一个</span><span style="font-size: 10pt; font-family: Verdana"><br />
</span><span style="font-size: 10pt; font-family: 宋体">星期五，</span><span style="font-size: 10pt; font-family: Verdana"><br />
<br />
The 'W' character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary of a month's days. The 'W' character can only be specified when the day-of-month is a single day, not a range or list of days<br />
. <br />
The 'L' and 'W' characters can also be combined for the day-of-month expression to yield 'LW', which translates to "last weekday of the month". <br />
<br />
The '#' character is allowed for the day-of-week field. This character is used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day-of-week field means the third Friday of the month (day 6 = Friday and "#3" = the 3rd one in the month). Other examples: "2#1" = the first Monday of the month and "4#5" = the fifth Wednesday of the month. Note that if you specify "#5" and there is not 5 of the given day-of-week in the month, then no firing will occur that month. <br />
<br />
The 'C' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "calendar". This means values are calculated against the associated calendar, if any. If no calendar is associated, then it is equivalent to having an all-inclusive calendar. A value of "5C" in the day-of-month field means "the first day included by the calendar on or after the 5th". A value of "1C" in the day-of-week field means "the first day included by the calendar on or after sunday". <br />
</span><span style="font-size: 10pt; font-family: 宋体">关于</span><span style="font-size: 10pt; font-family: Verdana">cronExpression</span><span style="font-size: 10pt; font-family: 宋体">的介绍</span><span style="font-size: 10pt; font-family: Verdana">:<br />
</span><span style="font-size: 10pt; font-family: 宋体">　</span><span style="font-size: 10pt; font-family: Verdana"> <br />
</span><span style="font-size: 10pt; font-family: 宋体">字段</span><span style="font-size: 10pt; font-family: 宋体">允许值</span><span style="font-size: 10pt; font-family: 宋体">允许的特殊字符</span><span style="font-size: 10pt; font-family: Verdana"> <br />
</span><span style="font-size: 10pt; font-family: 宋体">秒</span><span style="font-size: 10pt; font-family: Verdana"> 0-59 , - * / <br />
</span><span style="font-size: 10pt; font-family: 宋体">分</span><span style="font-size: 10pt; font-family: Verdana"> 0-59 , - * / <br />
</span><span style="font-size: 10pt; font-family: 宋体">小时</span><span style="font-size: 10pt; font-family: Verdana"> 0-23 , - * / <br />
</span><span style="font-size: 10pt; font-family: 宋体">日期</span><span style="font-size: 10pt; font-family: Verdana"> 1-31 , - * ? / L W C <br />
</span><span style="font-size: 10pt; font-family: 宋体">月份</span><span style="font-size: 10pt; font-family: Verdana"> 1-12 </span><span style="font-size: 10pt; font-family: 宋体">或者</span><span style="font-size: 10pt; font-family: Verdana"> JAN-DEC , - * / <br />
</span><span style="font-size: 10pt; font-family: 宋体">星期</span><span style="font-size: 10pt; font-family: Verdana"> 1-7 </span><span style="font-size: 10pt; font-family: 宋体">或者</span><span style="font-size: 10pt; font-family: Verdana"> SUN-SAT , - * ? / L C # <br />
</span><span style="font-size: 10pt; font-family: 宋体">年（可选）</span><span style="font-size: 10pt; font-family: 宋体">留空</span><span style="font-size: 10pt; font-family: Verdana">, 1970-2099 , - * / <br />
</span><span style="font-size: 10pt; font-family: 宋体">表达式意义</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 0 12 * * ?" </span><span style="font-size: 10pt; font-family: 宋体">每天中午</span><span style="font-size: 10pt; font-family: Verdana">12</span><span style="font-size: 10pt; font-family: 宋体">点触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 15 10 ? * *" </span><span style="font-size: 10pt; font-family: 宋体">每天上午</span><span style="font-size: 10pt; font-family: Verdana">10:15</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 15 10 * * ?" </span><span style="font-size: 10pt; font-family: 宋体">每天上午</span><span style="font-size: 10pt; font-family: Verdana">10:15</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 15 10 * * ? *" </span><span style="font-size: 10pt; font-family: 宋体">每天上午</span><span style="font-size: 10pt; font-family: Verdana">10:15</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 15 10 * * ? 2005" 2005</span><span style="font-size: 10pt; font-family: 宋体">年的每天上午</span><span style="font-size: 10pt; font-family: Verdana">10:15</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 * 14 * * ?" </span><span style="font-size: 10pt; font-family: 宋体">在每天下午</span><span style="font-size: 10pt; font-family: Verdana">2</span><span style="font-size: 10pt; font-family: 宋体">点到下午</span><span style="font-size: 10pt; font-family: Verdana">2:59</span><span style="font-size: 10pt; font-family: 宋体">期间的每</span><span style="font-size: 10pt; font-family: Verdana">1</span><span style="font-size: 10pt; font-family: 宋体">分钟触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 0/5 14 * * ?" </span><span style="font-size: 10pt; font-family: 宋体">在每天下午</span><span style="font-size: 10pt; font-family: Verdana">2</span><span style="font-size: 10pt; font-family: 宋体">点到下午</span><span style="font-size: 10pt; font-family: Verdana">2:55</span><span style="font-size: 10pt; font-family: 宋体">期间的每</span><span style="font-size: 10pt; font-family: Verdana">5</span><span style="font-size: 10pt; font-family: 宋体">分钟触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 0/5 14,18 * * ?" </span><span style="font-size: 10pt; font-family: 宋体">在每天下午</span><span style="font-size: 10pt; font-family: Verdana">2</span><span style="font-size: 10pt; font-family: 宋体">点到</span><span style="font-size: 10pt; font-family: Verdana">2:55</span><span style="font-size: 10pt; font-family: 宋体">期间和下午</span><span style="font-size: 10pt; font-family: Verdana">6</span><span style="font-size: 10pt; font-family: 宋体">点到</span><span style="font-size: 10pt; font-family: Verdana">6:55</span><span style="font-size: 10pt; font-family: 宋体">期间的每</span><span style="font-size: 10pt; font-family: Verdana">5</span><span style="font-size: 10pt; font-family: 宋体">分钟触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 0-5 14 * * ?" </span><span style="font-size: 10pt; font-family: 宋体">在每天下午</span><span style="font-size: 10pt; font-family: Verdana">2</span><span style="font-size: 10pt; font-family: 宋体">点到下午</span><span style="font-size: 10pt; font-family: Verdana">2:05</span><span style="font-size: 10pt; font-family: 宋体">期间的每</span><span style="font-size: 10pt; font-family: Verdana">1</span><span style="font-size: 10pt; font-family: 宋体">分钟触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 10,44 14 ? 3 WED" </span><span style="font-size: 10pt; font-family: 宋体">每年三月的星期三的下午</span><span style="font-size: 10pt; font-family: Verdana">2:10</span><span style="font-size: 10pt; font-family: 宋体">和</span><span style="font-size: 10pt; font-family: Verdana">2:44</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 15 10 ? * MON-FRI" </span><span style="font-size: 10pt; font-family: 宋体">周一至周五的上午</span><span style="font-size: 10pt; font-family: Verdana">10:15</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 15 10 15 * ?" </span><span style="font-size: 10pt; font-family: 宋体">每月</span><span style="font-size: 10pt; font-family: Verdana">15</span><span style="font-size: 10pt; font-family: 宋体">日上午</span><span style="font-size: 10pt; font-family: Verdana">10:15</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 15 10 L * ?" </span><span style="font-size: 10pt; font-family: 宋体">每月最后一日的上午</span><span style="font-size: 10pt; font-family: Verdana">10:15</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 15 10 ? * 6L" </span><span style="font-size: 10pt; font-family: 宋体">每月的最后一个星期五上午</span><span style="font-size: 10pt; font-family: Verdana">10:15</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 15 10 ? * 6L 2002-2005" 2002</span><span style="font-size: 10pt; font-family: 宋体">年至</span><span style="font-size: 10pt; font-family: Verdana">2005</span><span style="font-size: 10pt; font-family: 宋体">年的每月的最后一个星期五上午</span><span style="font-size: 10pt; font-family: Verdana">10:15</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
"0 15 10 ? * 6#3" </span><span style="font-size: 10pt; font-family: 宋体">每月的第三个星期五上午</span><span style="font-size: 10pt; font-family: Verdana">10:15</span><span style="font-size: 10pt; font-family: 宋体">触发</span><span style="font-size: 10pt; font-family: Verdana"> <br />
</span><span style="font-size: 10pt; font-family: 宋体">每天早上</span><span style="font-size: 10pt; font-family: Verdana">6</span><span style="font-size: 10pt; font-family: 宋体">点</span><span style="font-size: 10pt; font-family: Verdana"> <br />
0 6 * * * <br />
</span><span style="font-size: 10pt; font-family: 宋体">每两个小时</span><span style="font-size: 10pt; font-family: Verdana"> <br />
0 */2 * * * <br />
</span><span style="font-size: 10pt; font-family: 宋体">晚上</span><span style="font-size: 10pt; font-family: Verdana">11</span><span style="font-size: 10pt; font-family: 宋体">点到早上</span><span style="font-size: 10pt; font-family: Verdana">7</span><span style="font-size: 10pt; font-family: 宋体">点之间每两个小时，早上八点</span><span style="font-size: 10pt; font-family: Verdana"> <br />
0 23-7/2</span><span style="font-size: 10pt; font-family: 宋体">，</span><span style="font-size: 10pt; font-family: Verdana">8 * * * <br />
</span><span style="font-size: 10pt; font-family: 宋体">每个月的</span><span style="font-size: 10pt; font-family: Verdana">4</span><span style="font-size: 10pt; font-family: 宋体">号和每个礼拜的礼拜一到礼拜三的早上</span><span style="font-size: 10pt; font-family: Verdana">11</span><span style="font-size: 10pt; font-family: 宋体">点</span><span style="font-size: 10pt; font-family: Verdana"> <br />
0 11 4 * 1-3 <br />
1<span style="font-family: 宋体">月</span>1<span style="font-family: 宋体">日早上</span>4<span style="font-family: 宋体">点</span> <br />
0 4 1 1 *</span></p>
<p style="background: white; margin: 7.5pt 0cm; text-align: left" align="left"><span style="font-size: 10pt; font-family: Verdana">quartz</span><span style="font-size: 10pt; font-family: 宋体">的高级特性不仅如此</span><span style="font-size: 10pt; font-family: Verdana"> <br />
1 </span><span style="font-size: 10pt; font-family: 宋体">数据库存储</span><span style="font-size: 10pt; font-family: Verdana"> <br />
2 </span><span style="font-size: 10pt; font-family: 宋体">集群支持</span><span style="font-size: 10pt; font-family: Verdana"> <br />
3 </span><span style="font-size: 10pt; font-family: 宋体">数据库持久化任务，</span><span style="font-size: 10pt; font-family: Verdana">trigger <br />
4 trigger </span><span style="font-size: 10pt; font-family: 宋体">的停止，运行</span><span style="font-size: 10pt; font-family: Verdana"> <br />
5 </span><span style="font-size: 10pt; font-family: 宋体">任务的任意添加</span><span style="font-size: 10pt; font-family: Verdana"> <br />
6 </span><span style="font-size: 10pt; font-family: 宋体">比</span><span style="font-size: 10pt; font-family: Verdana">corntrigger </span><span style="font-size: 10pt; font-family: 宋体">更详尽的任务安排</span><span style="font-size: 10pt; font-family: Verdana"> <br />
7 </span><span style="font-size: 10pt; font-family: 宋体">线程的内部数据交换</span></p>
<p><br />
<br />
<br />
</p>
<p>&nbsp;</p>
<img src ="http://www.blogjava.net/Crying/aggbug/186636.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Crying/" target="_blank">Crying</a> 2008-03-16 18:20 <a href="http://www.blogjava.net/Crying/articles/186636.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>将GBK转换为UTF-8</title><link>http://www.blogjava.net/Crying/articles/174974.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Sun, 13 Jan 2008 06:17:00 GMT</pubDate><guid>http://www.blogjava.net/Crying/articles/174974.html</guid><wfw:comment>http://www.blogjava.net/Crying/comments/174974.html</wfw:comment><comments>http://www.blogjava.net/Crying/articles/174974.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Crying/comments/commentRss/174974.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Crying/services/trackbacks/174974.html</trackback:ping><description><![CDATA[<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;"><br />
</span><span style="color: #0000ff;">public</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">class</span><span style="color: #000000;">&nbsp;Test&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">public</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">static</span><span style="color: #000000;">&nbsp;String&nbsp;convertGBK2UTF8(String&nbsp;str)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;tmp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringBuffer&nbsp;sb&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">new</span><span style="color: #000000;">&nbsp;StringBuffer(</span><span style="color: #000000;">1000</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;c;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;i,&nbsp;j;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb.setLength(</span><span style="color: #000000;">0</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">&nbsp;(i&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;&nbsp;i&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">&nbsp;str.length();&nbsp;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;str.charAt(i);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(c&nbsp;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">255</span><span style="color: #000000;">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb.append(</span><span style="color: #000000;">"</span><span style="color: #000000;">\\u</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;(c&nbsp;</span><span style="color: #000000;">&gt;&gt;&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">8</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;Integer.toHexString(j);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(tmp.length()&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb.append(</span><span style="color: #000000;">"</span><span style="color: #000000;">0</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb.append(tmp);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;(c&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0xFF</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;Integer.toHexString(j);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(tmp.length()&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb.append(</span><span style="color: #000000;">"</span><span style="color: #000000;">0</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb.append(tmp);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb.append(c);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;(</span><span style="color: #0000ff;">new</span><span style="color: #000000;">&nbsp;String(sb));<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">public</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">static</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;main(String[]&nbsp;args)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&nbsp;&nbsp;&nbsp;&nbsp;Test.convertGBK2UTF8(</span><span style="color: #000000;">"</span><span style="color: #000000;">这是JAVAEE &amp; JIVE 组织&nbsp; ！</span><span style="color: #000000;">"</span><span style="color: #000000;">));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
}<br />
<br />
结果：\u8fd9\u662fJAVAEE&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">&nbsp;JIVE&nbsp;\u7ec4\u7ec7&nbsp;&nbsp;\uff01<br />
</span></div>
<img src ="http://www.blogjava.net/Crying/aggbug/174974.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Crying/" target="_blank">Crying</a> 2008-01-13 14:17 <a href="http://www.blogjava.net/Crying/articles/174974.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java中对日期的常用处理</title><link>http://www.blogjava.net/Crying/articles/173834.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Tue, 08 Jan 2008 15:27:00 GMT</pubDate><guid>http://www.blogjava.net/Crying/articles/173834.html</guid><wfw:comment>http://www.blogjava.net/Crying/comments/173834.html</wfw:comment><comments>http://www.blogjava.net/Crying/articles/173834.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/Crying/comments/commentRss/173834.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Crying/services/trackbacks/173834.html</trackback:ping><description><![CDATA[&nbsp;转：http://www.blogjava.net/jakin/archive/2008/01/08/173736.html<br />
<img src ="http://www.blogjava.net/Crying/aggbug/173834.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Crying/" target="_blank">Crying</a> 2008-01-08 23:27 <a href="http://www.blogjava.net/Crying/articles/173834.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Logger</title><link>http://www.blogjava.net/Crying/articles/173823.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Tue, 08 Jan 2008 14:39:00 GMT</pubDate><guid>http://www.blogjava.net/Crying/articles/173823.html</guid><wfw:comment>http://www.blogjava.net/Crying/comments/173823.html</wfw:comment><comments>http://www.blogjava.net/Crying/articles/173823.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Crying/comments/commentRss/173823.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Crying/services/trackbacks/173823.html</trackback:ping><description><![CDATA[&nbsp;Logger 对象用来记录特定系统或应用程序组件的日志消息。一般使用圆点分隔的层次名称空间来命名 Logger。<br />
<br />
一&nbsp;、&nbsp;<span style="color: red">java.util.logging.Logger&nbsp;&nbsp;</span>&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用某个 getLogger 工厂方法来获得 Logger 对象<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Logger log=Logger.getLogger(this.getClass().getName());<br />
<br />
二、 <span style="color: red">org.apache.log4j.Logger<br />
</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Logger log=Logger.getLogger(Hello.class);<br />
<br />
<br />
****************************************************************************************<br />
<br />
使用Log4j，第一步就是获取日志记录器，这个记录器将负责控制日志信息。其语法为：
<p>　　public static Logger getLogger( String name) </p>
<p>　　通过指定的名字获得记录器，如果必要的话，则为这个名字创建一个新的记录器。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name一般取本类的名字，比如： </p>
<p>　　static Logger logger = Logger.getLogger ( ServerWithLog4j.class.getName () )</p>
<p>　　②读取配置文件 </p>
<p>　　当获得了日志记录器之后，第二步将配置Log4j环境，其语法为：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BasicConfigurator.configure ()： 自动快速地使用缺省Log4j环境。<br />
　　PropertyConfigurator.configure ( String configFilename) ：读取使用Java的特性文件编写的配置文件。</p>
<p>例：PropertyConfigurator.configure(".\\src\\log4j.properties")<br />
　　DOMConfigurator.configure ( String filename ) ：读取XML形式的配置文件。</p>
<p>　　③插入记录信息（格式化日志信息）</p>
<p>　　当上两个必要步骤执行完毕，就可轻松地使用不同优先级别的日志记录语句插入到您想记录日<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 志的任何&nbsp;地&nbsp;方，其语法如下：</p>
<p>　　Logger.debug ( Object message ) ;<br />
　　Logger.info ( Object message ) ;<br />
　　Logger.warn ( Object message ) ;<br />
　　Logger.error ( Object message ) ;</p>
<p style="color: red">在web程序中使用log4j注意问题</p>
<p>1、&nbsp;&nbsp;&nbsp; 由于jsp或servlet在执行状态时没有当前路径概念，所有使用PropertyConfigurator.configure（String）语句找log4j.properties文件时要给出相对于当前jsp或servlet的路径转化成为一个绝对的文件系统路径。方法是使用 servletcontext.getrealpath(string)语句。例：</p>
<p>//得到当前jsp路径</p>
<p>String prefix =&nbsp; getServletContext().getRealPath("/");</p>
<p>//读取log4j.properties</p>
<p>PropertyConfigurator.configure(prefix+"\\WEB-INF\\log4j.properties");</p>
<p>2、相应的log4j.properties设置某个属性时也要在程序中设置绝对路径。例：</p>
<p>log4j.appender.R.File属性设置日志文件存放位置。我们可以用读写.properties配置文件的方法进行灵活设置。<br />
</p>
<p><br />
*********************************************************<br />
<br />
一个实例：<br />
一：<br />
</p>
<p>配置一个名为log4j.properties 文件,放到项目的src文件下面即可 <br />
log4j.rootLogger= INFO, A1 , R<br />
log4j.appender.A1=org.apache.log4j.ConsoleAppender <br />
log4j.appender.A1.layout=org.apache.log4j.PatternLayout <br />
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n <br />
log4j.appender.R=org.apache.log4j.RollingFileAppender<br />
#指定日志文件放的位置<br />
log4j.appender.R.File=D:/env/environment/webEnv/WEB-INF/log4j.log <br />
<br />
log4j.appender.R.MaxFileSize=100KB<br />
log4j.appender.R.MaxBackupIndex=1<br />
log4j.appender.R.layout=org.apache.log4j.PatternLayout<br />
#log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n<br />
log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] (%13F:%L) %3x - %m%n<br />
<br />
二：<br />
在src下建一个初始化的servlet让程序启动时加载log4j.properties文件</p>
<p>import javax.servlet.http.HttpServlet;<br />
import org.apache.log4j.Logger;<br />
import org.apache.log4j.PropertyConfigurator;</p>
<p>public class Log4jInit extends HttpServlet {</p>
<p>&nbsp;private static final long serialVersionUID = 1L;</p>
<p>&nbsp;public void init() {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;String prefix =&nbsp; getServletContext().getRealPath("/");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;String file = getInitParameter("log4j");<br />
&nbsp;<br />
&nbsp;&nbsp;// if the log4j-init-file is not set, then no point in trying&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;System.out.println("- Log4j start");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;if(file != null) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;PropertyConfigurator.configure(prefix+file);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;Logger _logger = Logger.getLogger (Log4jInit.class);<br />
&nbsp;&nbsp;_logger.info("- Log4j Test Successfully!");<br />
&nbsp;}<br />
}</p>
<p>&nbsp;三：在web.xml中配置这个Log4jInit .java这个servlet<br />
<br />
<br />
&lt;servlet&gt;<br />
&nbsp;&nbsp;&lt;servlet-name&gt;log4jlog4j-init&lt;/servlet-name&gt;<br />
&nbsp;&nbsp;&lt;servlet-class&gt;Log4jInit&lt;/servlet-class&gt;<br />
&nbsp;&nbsp;&lt;init-param&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;param-name&gt;log4j&lt;/param-name&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;param-value&gt;/WEB-INF/classes/log4j.properties&lt;/param-value&gt;<br />
&nbsp;&nbsp;&lt;/init-param&gt;<br />
&nbsp;&nbsp;&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;<br />
&nbsp;&lt;/servlet&gt;</p>
<p><br />
</p>
<br />
<br />
<br />
<img src ="http://www.blogjava.net/Crying/aggbug/173823.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Crying/" target="_blank">Crying</a> 2008-01-08 22:39 <a href="http://www.blogjava.net/Crying/articles/173823.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于序列化Serializable </title><link>http://www.blogjava.net/Crying/articles/159263.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Fri, 09 Nov 2007 01:20:00 GMT</pubDate><guid>http://www.blogjava.net/Crying/articles/159263.html</guid><wfw:comment>http://www.blogjava.net/Crying/comments/159263.html</wfw:comment><comments>http://www.blogjava.net/Crying/articles/159263.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Crying/comments/commentRss/159263.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Crying/services/trackbacks/159263.html</trackback:ping><description><![CDATA[<div id="art" style="margin: 15px">
<p>个人看法，不一定正确 <br />
你是女生，有没有接触过毛线团<br />
毛线团就是我们实现了Serializable接口的对象<br />
一个毛线团可以抽成很长的毛线<br />
又可以把很长的毛线卷成毛线团<br />
对应起来就是<br />
一个巨大的对象可以抽成很简单的文本表达保存起来<br />
需要使用这个对象的时候<br />
再根据这些文本生成<br />
Serializable 只是一个标志，让JVM能够知道可以安全的把object转化成上面老兄说的毛线团。<br />
你不需要作任何code。<br />
Serializable 对JAVABEANS是必须的接口。<br />
你不需要作任何实现。</p>
<p>序列化是把一个对象的状态写入一个字节流的过程，它执行RMI，RMI允许一台机器上的JAVA对象调用不同机器上的JAVA对象方法，对象可以作为参数提供给那个远程方法，发送机序列化该对象并传送它，接收机执行反序列化。<br />
序列化和反序列化的关系图表可形成包含循环引用的顺序图表。这是整个序列化的总体思想。<br />
而Serializable接口属于支持序列化的一个接口，只有一个实现它的对象可以被序列化工具存储和回复，Serializable接口没有定义任何成员，只用来表示一个累可以被序列化，若该类可以序列化，那么它的所有子类都可以。<br />
下面是关于序列化的一个实例：<br />
[b:a55efb5f91]程序名称：SerializationDemo.java<br />
程序主题：实现对象的序列化和反序列化<br />
程序说明：该程序由实例化一个MyClass类的对象开始，该对象有三个实例变量，类型分别为String、int、double，是希望存储和恢复的信息。[/b:a55efb5f91]</p>
<p>[code:1:a55efb5f91]</p>
<p>import java.io.*;</p>
<p>public class SerializationDemo{</p>
<p>public static void main(String args[]){</p>
<p>//Object serialization<br />
&nbsp;try{<br />
&nbsp;&nbsp;MyClass object1=new MyClass("Hello",-7,2.7e10);<br />
&nbsp;&nbsp;System.out.println("object1:"+object1);<br />
&nbsp;&nbsp;FileOutputStream fos=new FileOutputStream("serial");<br />
&nbsp;&nbsp;ObjectOutputStream oos=new ObjectOutputStream(fos);<br />
&nbsp;&nbsp;oos.writeObject(object1);<br />
&nbsp;&nbsp;oos.flush();<br />
&nbsp;&nbsp;oos.close();<br />
&nbsp;}<br />
&nbsp;catch(Exception e){<br />
&nbsp;&nbsp;System.out.println("Exception during serialization:"+e);<br />
&nbsp;&nbsp;System.exit(0);<br />
&nbsp;}</p>
<p>&nbsp;//Object deserialization<br />
&nbsp;try{<br />
&nbsp;&nbsp;MyClass object2;<br />
&nbsp;&nbsp;FileInputStream fis=new FileInputStream("serial");<br />
&nbsp;&nbsp;ObjectInputStream ois=new ObjectInputStream(fis);<br />
&nbsp;&nbsp;object2=(MyClass)ois.readObject();<br />
&nbsp;&nbsp;ois.close();<br />
&nbsp;&nbsp;System.out.println("object2:"+object2);<br />
&nbsp;}<br />
&nbsp;catch(Exception e){<br />
&nbsp;&nbsp;System.out.println("Exception during deserialization:"+e);<br />
&nbsp;&nbsp;System.exit(0);<br />
&nbsp;}<br />
&nbsp; }<br />
}</p>
<p>class MyClass implements Serializable{<br />
&nbsp;String s;<br />
&nbsp;int i;<br />
&nbsp;double d;<br />
&nbsp;public MyClass(String s,int i,double d){<br />
&nbsp;&nbsp;this.s=s;<br />
&nbsp;&nbsp;this.i=i;<br />
&nbsp;&nbsp;this.d=d;<br />
&nbsp;}<br />
&nbsp;public String toString(){<br />
&nbsp;&nbsp;return "s="+s+";i="+i+";d="+d;<br />
&nbsp;}<br />
}<br />
[/code:1:a55efb5f91]</p>
<p>程序运行结果：object1和object2的实例变量是一样的，输出如下：[code:1:a55efb5f91]object1:s=Hello;i=-7;d=2.7E10<br />
object2:s=Hello;i=-7;d=2.7E10[/code:1:a55efb5f91]<br />
&lt;!--========================================================--&gt;<br />
hehe<br />
未必是RMI啦<br />
持久化也是Serializable的重点...<br />
&lt;!--========================================================--&gt;<br />
//agree<br />
持久化是Serializable开始的目的。<br />
楼主有什么心得，是不是也response一下？<br />
&lt;!--========================================================--&gt;<br />
现在知道是怎么回事了-----Thank Bruce Eckel a million times for his excellent &lt;&lt;Think in java(Second Edition) &gt;&gt;.书里面讲的好清楚啊。<br />
一。猫小写的不大全，可能是因为我的帖子里写的&#8220;一般在什么情况下用&#8221;这话作怪。<br />
我补充一下：<br />
Object serialization的定义：<br />
Object serialization 允许你将实现了Serializable接口的对象转换为字节序列，这些字节序列可以被完全存储以备以后重新生成原来的对象。 </p>
<p>serialization不但可以在本机做，而且可以经由网络操作（就是猫小说的RMI）。这个好处是很大的----因为它自动屏蔽了操作系统的差异，字节顺序（用Unix下的c开发过网络编程的人应该知道这个概念，我就容易在这上面犯错）等。比如，在Window平台生成一个对象并序列化之，然后通过网络传到一台Unix机器上，然后可以在这台Unix机器上正确地重构这个对象。</p>
<p>Object serialization主要用来支持2种主要的特性：<br />
1。Java的RMI(remote method invocation).RMI允许象在本机上一样操作远程机器上的对象。当发送消息给远程对象时，就需要用到serializaiton机制来发送参数和接收返回直。</p>
<p>2。Java的JavaBeans.&nbsp;&nbsp; Bean的状态信息通常是在设计时配置的。Bean的状态信息必须被存起来，以便当程序运行时能恢复这些状态信息。这也需要serializaiton机制。</p>
<p>二。sakulagi和rollingpig说的持久化我也说一下。<br />
我觉得你们说的应该是英文里的persistence.但是Java语言里现在只支持lightweight persistence,就是轻量级持久化，这是通过serialization机制来实现的。</p>
<p>persistence是指一个对象的生命周期不由程序是否执行来决定，即使是在程序终止时这个对象也存在。它把一个serializable的对象写到磁盘（本机或其他机器上的非RAM存储器），并在程序重新调用时再读取对象到通常的RAM存储器。</p>
<p>为什么说Java的serialization机制实现的是lightweight persistence?因为你必须显式的序列化和反序列化程序里的对象；而不是直接由一个关键词来定义一个对象是序列化的然后由系统做相应的处理。&nbsp; 如果以后的Java版本出现一个新的关键字来实现这种机制，比如就是persistence,如果我用</p>
<p>persistence&nbsp; (String s="chinaunix")</p>
<p>然后系统自动做猫小程序里的那些处理，那么Java就实现了persistence.</p>
<p>第一次写这么多，而且是刚看了书不久写的，错误和行文不当之处多包涵。</p>
<p>再次感谢猫小,sakulagi和rollingpig给的提示。<br />
&lt;!--========================================================--&gt;<br />
Joshua Bloch 的 "Effective Java Programming Language Guide" 里面关于 Serializable 的部分讲得也很好，尤其是什么时候该用，什么时候不该用。<br />
&lt;!--========================================================--&gt;<br />
&nbsp;关于序列化处理Bean的状态信息能不能说的详细具体一些呢，谢谢！<br />
&lt;!--========================================================--&gt;<br />
这儿我没有写过，我想是通过序列化bean，进行writeObject方法可以将数据写入数据库的一个表。<br />
oracle对这点有支持。 <br />
</p>
<div></div>
</div>
<img src ="http://www.blogjava.net/Crying/aggbug/159263.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Crying/" target="_blank">Crying</a> 2007-11-09 09:20 <a href="http://www.blogjava.net/Crying/articles/159263.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>理解JAVA多态 </title><link>http://www.blogjava.net/Crying/articles/159257.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Fri, 09 Nov 2007 01:19:00 GMT</pubDate><guid>http://www.blogjava.net/Crying/articles/159257.html</guid><wfw:comment>http://www.blogjava.net/Crying/comments/159257.html</wfw:comment><comments>http://www.blogjava.net/Crying/articles/159257.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Crying/comments/commentRss/159257.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Crying/services/trackbacks/159257.html</trackback:ping><description><![CDATA[<div>数据抽象、继承和多态是面向对象程序设计语言的三大特性。多态，我觉得它的作用就是用来将接口和实现分离开，改善代码的组织结构，增强代码的可读性。在某些很简单的情况下，或许我们不使用多态也能开发出满足我们需要的程序，但大多数情况，如果没有多态，就会觉得代码极其难以维护。</div>
<div>在Java中，谈论多态就是在讨论方法调用的绑定，绑定就是将一个方法调用同一个方法主体关联起来。在C语言中，方法(在C中称为函数)的绑定是由编译器来实现的，在英文中称为early binding(前期绑定)，因此，大家自然就会想到相对应的late binding(后期绑定)，这在Java中通常叫做run-time binding(运行时绑定)，我个人觉得这样称呼更贴切，运行时绑定的目的就是在代码运行的时候能够判断对象的类型。通过一个简单的例子说明：</div>
<div>/**<br />
&nbsp;* 定义一个基类<br />
&nbsp;*/<br />
public Class Parents {<br />
&nbsp;public void print() {<br />
&nbsp;&nbsp;System.out.println(&#8220;parents&#8221;);<br />
&nbsp;}<br />
}</div>
<div>/**<br />
&nbsp;* 定义两个派生类<br />
&nbsp;*/<br />
public Class Father extends Parents {<br />
&nbsp;public void print() {<br />
&nbsp;&nbsp;System.out.println(&#8220;father&#8221;);<br />
&nbsp;}<br />
}</div>
<div>public Class Mother extends Parents {<br />
&nbsp;public void print() {<br />
&nbsp;&nbsp;System.out.println(&#8220;mother&#8221;);<br />
&nbsp;}<br />
}</div>
<div>/**<br />
&nbsp;* 测试输出结果的类<br />
&nbsp;*/<br />
public Class Test {<br />
&nbsp;public void find(Parents p) {<br />
&nbsp;&nbsp;p.print();<br />
&nbsp;}</div>
<div>&nbsp;public static void main(String[] args) {<br />
&nbsp;&nbsp;Test t = new Test();<br />
&nbsp;&nbsp;Father f = new Father();<br />
&nbsp;&nbsp;Mother m = new Mother();<br />
&nbsp;&nbsp;t.find(f);<br />
&nbsp;&nbsp;t.find(m);<br />
&nbsp;}<br />
}</div>
<div>最后的输出结果分别是father和mother，将派生类的引用传给基类的引用，然后调用重写方法，基类的引用之所以能够找到应该调用那个派生类的方法，就是因为程序在运行时进行了绑定。</div>
<div>学过Java基础的人都能很容易理解上面的代码和多态的原理，但是仍有一些关键的地方需要注意的，算是自己对多态的一个小结：</div>
<div>1.Java中除了static和final方法外，其他所有的方法都是运行时绑定的。在我另外一篇文章中说到private方法都被隐式指定为final的，因此final的方法不会在运行时绑定。当在派生类中重写基类中static、final、或private方法时，实质上是创建了一个新的方法<br />
2.在派生类中，对于基类中的private方法，最好采用不同的名字。<br />
3.包含抽象方法的类叫做抽象类。注意定义里面包含这样的意思，只要类中包含一个抽象方法，该类就是抽象类。抽象类在派生中就是作为基类的角色，为不同的子类提供通用的接口。<br />
4.对象清理的顺序和创建的顺序相反，当然前提是自己想手动清理对象，因为大家都知道Java垃圾回收器。<br />
5.在基类的构造方法中小心调用基类中被重写的方法，这里涉及到对象初始化顺序。<br />
6.构造方法是被隐式声明为static方法。<br />
7.用继承表达行为间的差异，用字段表达状态上的变化。 <br />
</div>
<img src ="http://www.blogjava.net/Crying/aggbug/159257.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Crying/" target="_blank">Crying</a> 2007-11-09 09:19 <a href="http://www.blogjava.net/Crying/articles/159257.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SimpleDateFormat详解</title><link>http://www.blogjava.net/Crying/articles/159255.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Fri, 09 Nov 2007 01:16:00 GMT</pubDate><guid>http://www.blogjava.net/Crying/articles/159255.html</guid><wfw:comment>http://www.blogjava.net/Crying/comments/159255.html</wfw:comment><comments>http://www.blogjava.net/Crying/articles/159255.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Crying/comments/commentRss/159255.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Crying/services/trackbacks/159255.html</trackback:ping><description><![CDATA[<p>public class SimpleDateFormat extends DateFormat<br />
SimpleDateFormat 是一个以国别敏感的方式格式化和分析数据的具体类。 它允许格式化 (date -&gt; text)、语法分析 (text -&gt; date)和标准化。 </p>
<p>SimpleDateFormat 允许以为日期-时间格式化选择任何用户指定的方式启动。 但是，希望用 DateFormat 中的 getTimeInstance、 getDateInstance 或 getDateTimeInstance 创建一个日期-时间格式化程序。 每个类方法返回一个以缺省格式化方式初始化的日期／时间格式化程序。 可以根据需要用 applyPattern 方法修改格式化方式。 </p>
<p>SimpleDateFormat函数的继承关系：<br />
java.lang.Object<br />
&nbsp;&nbsp; |<br />
&nbsp;&nbsp; +----java.text.Format<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +----java.text.DateFormat<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +----java.text.SimpleDateFormat<br />
下面是个小例子：<br />
import java.text.*;<br />
import java.util.Date;</p>
<p>/**<br />
&nbsp; SimpleDateFormat函数语法：<br />
&nbsp; <br />
&nbsp; G 年代标志符<br />
&nbsp; y 年<br />
&nbsp; M 月<br />
&nbsp; d 日<br />
&nbsp; h 时 在上午或下午 (1~12)<br />
&nbsp; H 时 在一天中 (0~23)<br />
&nbsp; m 分<br />
&nbsp; s 秒<br />
&nbsp; S 毫秒<br />
&nbsp; E 星期<br />
&nbsp; D 一年中的第几天<br />
&nbsp; F 一月中第几个星期几<br />
&nbsp; w 一年中第几个星期<br />
&nbsp; W 一月中第几个星期<br />
&nbsp; a 上午 / 下午 标记符 <br />
&nbsp; k 时 在一天中 (1~24)<br />
&nbsp; K 时 在上午或下午 (0~11)<br />
&nbsp; z 时区<br />
&nbsp;*/<br />
public class FormatDateTime {</p>
<p>&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleDateFormat myFmt=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleDateFormat myFmt1=new SimpleDateFormat("yy/MM/dd HH:mm"); <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//等价于now.toLocaleString()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleDateFormat myFmt3=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 E ");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleDateFormat myFmt4=new SimpleDateFormat(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "一年中的第 D 天 一年中第w个星期 一月中第W个星期 在一天中k时 z时区");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date now=new Date();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(myFmt.format(now));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(myFmt1.format(now));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(myFmt2.format(now));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(myFmt3.format(now));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(myFmt4.format(now));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(now.toGMTString());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(now.toLocaleString());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(now.toString());<br />
&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; <br />
}</p>
<p>效果：<br />
2007年10月16日 17时24分27秒<br />
07/10/16 17:24<br />
200-10-16 17:24:27<br />
2007年10月16日 17时24分27秒 星期四 <br />
一年中的第 351 天 一年中第51个星期 一月中第3个星期 在一天中17时 CST时区<br />
16 Dec 2007 09:24:27 GMT<br />
2007-10-16 17:24:27<br />
Thu Dec 16 17:24:27 CST 200</p>
<p>下面是个JavaBean:<br />
public class FormatDateTime {<br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; public static String toLongDateString(Date dt){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleDateFormat myFmt=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 E ");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return myFmt.format(dt);<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; public static String toShortDateString(Date dt){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleDateFormat myFmt=new SimpleDateFormat("yy年MM月dd日 HH时mm分");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return myFmt.format(dt);<br />
&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; public static String toLongTimeString(Date dt){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleDateFormat myFmt=new SimpleDateFormat("HH mm ss SSSS");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return myFmt.format(dt);<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; public static String toShortTimeString(Date dt){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SimpleDateFormat myFmt=new SimpleDateFormat("yy/MM/dd HH:mm");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return myFmt.format(dt);<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date now=new Date();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(FormatDateTime.toLongDateString(now));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(FormatDateTime.toShortDateString(now));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(FormatDateTime.toLongTimeString(now));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(FormatDateTime.toShortTimeString(now));<br />
&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; <br />
}<br />
调用的main 测试结果：<br />
2007年12月16日 17时38分26秒 星期四 <br />
07年12月16日 17时38分<br />
17 38 26 0965<br />
07/12/16 17:38</p>
<img src ="http://www.blogjava.net/Crying/aggbug/159255.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Crying/" target="_blank">Crying</a> 2007-11-09 09:16 <a href="http://www.blogjava.net/Crying/articles/159255.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于数组和List之间相互转换的方法 </title><link>http://www.blogjava.net/Crying/articles/159254.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Fri, 09 Nov 2007 01:13:00 GMT</pubDate><guid>http://www.blogjava.net/Crying/articles/159254.html</guid><wfw:comment>http://www.blogjava.net/Crying/comments/159254.html</wfw:comment><comments>http://www.blogjava.net/Crying/articles/159254.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Crying/comments/commentRss/159254.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Crying/services/trackbacks/159254.html</trackback:ping><description><![CDATA[<div>1.List转换成为数组。（这里的List是实体是ArrayList)<br />
调用ArrayList的toArray方法。<br />
toArray<br />
public &lt;T&gt; T[] toArray(T[] a)返回一个按照正确的顺序包含此列表中所有元素的数组；返回数组的运行时类型就是指定数组的运行时类型。如果列表能放入指定的数组，则返回放入此列表元素的数组。否则，将根据指定数组的运行时类型和此列表的大小分配一个新的数组。<br />
如果指定的数组能容纳列表并有剩余空间（即数组的元素比列表的多），那么会将数组中紧跟在集合末尾的元素设置为 null。这对确定列表的长度很有用，但只 在调用方知道列表中不包含任何 null 元素时才有用。 <br />
指定者：<br />
接口 Collection&lt;E&gt; 中的 toArray<br />
指定者：<br />
接口 List&lt;E&gt; 中的 toArray<br />
覆盖：<br />
类 AbstractCollection&lt;E&gt; 中的 toArray<br />
参数：<br />
a - 要存储列表元素的数组，如果它足够大的话；否则，它是一个为存储列表元素而分配的、具有相同运行时类型的新数组。 <br />
返回：<br />
包含列表元素的数组。 <br />
抛出： <br />
ArrayStoreException - 如果 a 的运行时类型不是此列表中每个元素的运行时类型的超类型。</div>
<div>具体用法：<br />
import java.util.Arrays;<br />
import java.util.List;</div>
<div>{<br />
List list = new ArrayList();<br />
list.add("1");<br />
list.add("2");<br />
final int size =&nbsp; list.size();<br />
String[] arr = (String[])list.toArray(new String[size]);<br />
}<br />
&nbsp;</div>
<div>2.数组转换成为List。<br />
调用Arrays的asList方法.<br />
asList<br />
public static &lt;T&gt; List&lt;T&gt; asList(T... a)返回一个受指定数组支持的固定大小的列表。（对返回列表的更改会&#8220;直写&#8221;到数组。）此方法同 Collection.toArray 一起，充当了基于数组的 API 与基于 collection 的 API 之间的桥梁。返回的列表是可序列化的，并且实现了 RandomAccess。 <br />
此方法还提供了一个创建固定长度的列表的便捷方法，该列表被初始化为包含多个元素： <br />
import java.util.Arrays;<br />
import java.util.List;</div>
<div>{<br />
&nbsp;&nbsp;&nbsp;&nbsp; List stooges = Arrays.asList("Larry", "Moe", "Curly");<br />
&nbsp;}<br />
参数：<br />
a - 支持列表的数组。 <br />
返回：<br />
指定数组的列表视图。<br />
另请参见：<br />
Collection.toArray()</div>
<div>具体用法:<br />
String[] arr = new String[] {"1", "2"};<br />
List list = Arrays.asList(arr);</div>
<img src ="http://www.blogjava.net/Crying/aggbug/159254.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Crying/" target="_blank">Crying</a> 2007-11-09 09:13 <a href="http://www.blogjava.net/Crying/articles/159254.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>== 和equals区别</title><link>http://www.blogjava.net/Crying/articles/149971.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Sun, 30 Sep 2007 10:39:00 GMT</pubDate><guid>http://www.blogjava.net/Crying/articles/149971.html</guid><wfw:comment>http://www.blogjava.net/Crying/comments/149971.html</wfw:comment><comments>http://www.blogjava.net/Crying/articles/149971.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Crying/comments/commentRss/149971.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Crying/services/trackbacks/149971.html</trackback:ping><description><![CDATA[<div>先看下面代码：</div>
<div><span class="Code">
<div>class Test1<br />
{<br />
public static void main(String args[])<br />
&nbsp; {<br />
&nbsp;&nbsp;&nbsp; int a = 10;<br />
&nbsp;&nbsp;&nbsp; int b = 10;<br />
&nbsp;&nbsp;&nbsp; System.out.println("a is " + a);<br />
&nbsp;&nbsp;&nbsp; System.out.println("b is " + b);<br />
&nbsp;&nbsp;&nbsp; System.out.println("a==b is " + (a==b));//1 true</div>
<div>&nbsp;&nbsp;&nbsp; Integer ia = new Integer(10);<br />
&nbsp;&nbsp;&nbsp; Integer ib = new Integer(10);<br />
&nbsp;&nbsp;&nbsp; System.out.println("ia is " + ia);<br />
&nbsp;&nbsp;&nbsp; System.out.println("ib is " + ib);<br />
&nbsp;&nbsp;&nbsp; System.out.println("ia==ib is " + (ia==ib));//2 false </div>
<div>&nbsp;&nbsp;&nbsp; System.out.println("ia.equals(ib) is " + (ia.equals(ib)));//3 true<br />
&nbsp;&nbsp;&nbsp; System.out.println("ib.equals(ia) is " + (ib.equals(ia)));//3 true<br />
&nbsp; }<br />
}</div>
</span>==和equals的用法总结如下：<br />
1. 用==测试两个Primitive type是否完全相同，如代码中1处所示，或测试两个object refrencees 是否指向同一个对象，如代码中2处所示<br />
2. 用equals比较两个对象的内容是否相同。如代码中3处所示。</div>
<div>需要注意的是上述比较都针对的是同一种类型的基本数据或对象，如果是不同类型之间的比较，看如下代码：</div>
<div><span class="Code">
<div>class Test2<br />
{<br />
&nbsp; public static void main(String args[])<br />
&nbsp; {<br />
&nbsp;&nbsp;&nbsp; int a = 10;<br />
&nbsp;&nbsp;&nbsp; float b = 10.0f;<br />
&nbsp;&nbsp;&nbsp; System.out.println("a is " + a);<br />
&nbsp;&nbsp;&nbsp; System.out.println("b is " + b);<br />
&nbsp;&nbsp;&nbsp; System.out.println("a==b is " + (a==b));//1 true</div>
<div>&nbsp;&nbsp;&nbsp; Integer ia = new Integer(10);<br />
&nbsp;&nbsp;&nbsp; Float fa = new Float(10.0f);<br />
&nbsp;&nbsp;&nbsp; System.out.println("ia is " + ia);<br />
&nbsp;&nbsp;&nbsp; System.out.println("fa is " + fa);<br />
&nbsp;&nbsp;&nbsp; System.out.println("ia.equals(fa) is " + (ia.equals(fa)));//2 false<br />
&nbsp;&nbsp;&nbsp; System.out.println("fa.equals(ia) is " + (fa.equals(ia)));//2 false <br />
&nbsp; }<br />
}</div>
</span>1. 当程序比较基本类型数据 int a 和 float b 时，会将int 晋升为一个float ,此时10变成10.0，并认为二者是相等的，如代码中1处所示。<br />
2. 两个隶属不同classes 的对象绝不会相等，除非你自己实现一个equals()方法。<br />
&nbsp;&nbsp; 注意上述代码中2处编译通得过，而且不会抛出任何异常，都返回false 。</div>
<div>------------------------------------------------------------------------------------<br />
附：String对象的2种创建过程。<br />
示例代码：<br />
<span class="Code">
<div>public class StringInitial{<br />
&nbsp;public static void main(String[] args){<br />
&nbsp;&nbsp;String s1="hebing";<br />
&nbsp;&nbsp;String s2="hebing";<br />
&nbsp;&nbsp;String s3="he";<br />
&nbsp;&nbsp;String s4=new String("hebing");<br />
&nbsp;&nbsp;String s5=new String("hebing");</div>
<div>&nbsp;&nbsp;System.out.println("String:");<br />
&nbsp;&nbsp;System.out.println("s12---"+s1.equals(s2)+"----"+(s1==s2));<br />
&nbsp;&nbsp;System.out.println("s1:hebing---"+s1.equals("hebing")+"----"+(s1=="hebing"));<br />
&nbsp;&nbsp;System.out.println("hebing:he-----"+s1.equals(s3));<br />
&nbsp;&nbsp;System.out.println("s14----"+s1.equals(s4)+"----"+(s1==s4));<br />
&nbsp;&nbsp;System.out.println("s4:hebing----"+s4.equals("hebing")+"----"+(s4=="hebing"));<br />
&nbsp;&nbsp;System.out.println("s45----"+s4.equals(s5)+"----"+(s4==s5));</div>
<div>&nbsp;}<br />
}</div>
</span>1. String s1 = "immutable";的创建过程<br />
&nbsp;&nbsp;&nbsp; 用字符串常量创建String型的对象时，在编译时，编译器向字符串常量缓冲区中添加该常量，<br />
如果还有String s2 = "immutable";编译器会先判断缓冲区中是否有此常量，有的话就不会创建新的，而直接使用已有的字符串常量。这样s1 和 s2 就指向了同一个地址，两者的内容也都相同，即用== 和equals()方法比较都是true</div>
<div>2. String s2 = new String("Constructed");的创建过程<br />
&nbsp;&nbsp;&nbsp; 当这行代码被编译时，字符串常量"Constructed"先被放进缓冲区中，到了运行时，new String()语句被执行，一个新的String实例被创建，并复制缓冲区中的字符串到新分配的内存空间中，最后新建的String对象被赋予s2,<br />
显然，用new String()语句将导致额外的内存分配。至于常量缓冲区是存放在哪的，参见下面这篇讨论：<br />
http://community.csdn.net/Expert/TopicView3.asp?id=4245026<br />
<br />
<br />
/***********************************************************************/<br />
<br />
<p>==操作符专门用来比较变量的值是否相等。比较好理解的一点是： <br />
<br />
　　int a=10; <br />
　　int b=10; <br />
<br />
　　则a==b将是true。 <br />
<br />
　　但不好理解的地方是： <br />
<br />
<br />
　　String a=new String("foo"); <br />
　　String b=new String("foo"); <br />
<br />
　　则a==b将返回false。 <br />
<br />
　　对象变量其实是一个引用，它们的值是指向对象所在的内存地址，而不是对象本身。a和b都使用了new操作符，意味着将在内存中产生两个内容为"foo"的字符串，既然是&#8220;两个&#8221;，它们自然位于不同的内存地址。a和b的值其实是两个不同的内存地址的值，所以使用"=="操作符，结果会是false。诚然，a和b所指的对象，它们的内容都是"foo"，应该是&#8220;相等&#8221;，但是==操作符并不涉及到对象内容的比较。 <br />
<br />
　　对象内容的比较，正是equals方法做的事。 <br />
<br />
　　看一下Object对象的equals方法是如何实现的： <br />
<br />
　　boolean equals(Object o){ <br />
<br />
　　return this==o; <br />
<br />
　　} <br />
<br />
　　Object对象默认使用了==操作符。所以如果你自创的类没有覆盖equals方法，那你的类使用equals和使用==会得到同样的结果。同样也可以看出，Object的equals方法没有达到equals方法应该达到的目标：比较两个对象内容是否相等。因为答案应该由类的创建者决定，所以Object把这个任务留给了类的创建者。 <br />
<br />
　　看一下一个极端的类： <br />
<br />
<br />
　　Class Monster{ <br />
　　private String content; <br />
　　... <br />
　　boolean equals(Object another){ return true;} <br />
<br />
　　} <br />
<br />
　　我覆盖了equals方法。这个实现会导致无论Monster实例内容如何，它们之间的比较永远返回true。 <br />
<br />
　　所以当你是用equals方法判断对象的内容是否相等，请不要想当然。因为可能你认为相等，而这个类的作者不这样认为，而类的equals方法的实现是由他掌握的。如果你需要使用equals方法，或者使用任何基于散列码的集合（HashSet,HashMap,HashTable），请察看一下java doc以确认这个类的equals逻辑是如何实现的。 </p>
</div>
 <img src ="http://www.blogjava.net/Crying/aggbug/149971.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Crying/" target="_blank">Crying</a> 2007-09-30 18:39 <a href="http://www.blogjava.net/Crying/articles/149971.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>