﻿<?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-清睛仪明-文章分类-J2EE</title><link>http://www.blogjava.net/msmary/category/26490.html</link><description>书山有路勤为径，学海无涯苦作舟</description><language>zh-cn</language><lastBuildDate>Thu, 25 Oct 2007 12:42:23 GMT</lastBuildDate><pubDate>Thu, 25 Oct 2007 12:42:23 GMT</pubDate><ttl>60</ttl><item><title>AOP是什么</title><link>http://www.blogjava.net/msmary/articles/155418.html</link><dc:creator>谭明</dc:creator><author>谭明</author><pubDate>Tue, 23 Oct 2007 14:55:00 GMT</pubDate><guid>http://www.blogjava.net/msmary/articles/155418.html</guid><wfw:comment>http://www.blogjava.net/msmary/comments/155418.html</wfw:comment><comments>http://www.blogjava.net/msmary/articles/155418.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/msmary/comments/commentRss/155418.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/msmary/services/trackbacks/155418.html</trackback:ping><description><![CDATA[<p>&nbsp; </p>
<p style="line-height: 150%; text-align: left" align="left"><strong><span style="color: #212121; font-family: 宋体">为什么要区分</span></strong><strong><span style="color: #212121; font-family: Verdana">J2EE</span></strong><strong><span style="color: #212121; font-family: 宋体">容器和</span></strong><strong><span style="color: #212121; font-family: Verdana">J2EE</span></strong><strong><span style="color: #212121; font-family: 宋体">应用系统？</span></strong></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　我们知道，</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">应用系统只有部署在</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">容器中才能运行，那么为什么划分为</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">容器和</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">应用系统？</span><span style="color: #212121; line-height: 150%; font-family: 宋体">通过对</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">容器运行机制的分析（见我的电子教材</span><span style="color: #212121; line-height: 150%; font-family: Verdana">&#8220;EJB</span><span style="color: #212121; line-height: 150%; font-family: 宋体">实用原理</span><span style="color: #212121; line-height: 150%; font-family: Verdana">&#8221;</span><span style="color: #212121; line-height: 150%; font-family: 宋体">），我们可以发现：实际上</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">容器分离了一般应用系统的一些通用功能，例如事务机制、安全机制以及对象池或线程池等性能优化机制。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　这些功能机制是每个应用系统几乎都需要的，因此可以从具体应用系统中分离出来，形成一个通用的框架平台，而且，这些功能机制的设计开发有一定难度，同时运行的稳定性和快速性都非常重要，必须经过长时间调试和运行经验积累而成，因此，形成了专门的</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">容器服务器产品，如</span><span style="color: #212121; line-height: 150%; font-family: Verdana">Tomcat JBoss</span><span style="color: #212121; line-height: 150%; font-family: 宋体">、</span><span style="color: #212121; line-height: 150%; font-family: Verdana">Websphere</span><span style="color: #212121; line-height: 150%; font-family: 宋体">、</span><span style="color: #212121; line-height: 150%; font-family: Verdana">WebLogic</span><span style="color: #212121; line-height: 150%; font-family: 宋体">等。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　从</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">系统划分为</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">容器和</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">应用系统两个方面，我们已经看到一种分散关注的思路（</span><span style="color: #212121; line-height: 150%; font-family: Verdana">separation of concerns</span><span style="color: #212121; line-height: 150%; font-family: 宋体">）。</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<br />
</span><strong><span style="color: #212121; font-family: 宋体">分散关注</span></strong><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<br />
</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　　将通用需求功能从不相关类之中分离出来；同时，能够使得很多类共享一个行为，一旦行为发生变化，不必修改很多类，只要修改这个行为就可以。</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<br />
</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　　</span><span style="color: #212121; line-height: 150%; font-family: Verdana"> AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">就是这种实现分散关注的编程方法，它将</span><span style="color: #212121; line-height: 150%; font-family: Verdana">&#8220;</span><span style="color: #212121; line-height: 150%; font-family: 宋体">关注</span><span style="color: #212121; line-height: 150%; font-family: Verdana">&#8221;</span><span style="color: #212121; line-height: 150%; font-family: 宋体">封装在</span><span style="color: #212121; line-height: 150%; font-family: Verdana">&#8220;</span><span style="color: #212121; line-height: 150%; font-family: 宋体">方面</span><span style="color: #212121; line-height: 150%; font-family: Verdana">&#8221;</span><span style="color: #212121; line-height: 150%; font-family: 宋体">中。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><strong><span style="color: #212121; font-family: Verdana">AOP</span></strong><strong><span style="color: #212121; font-family: 宋体">是什么？</span></strong></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">是</span><span style="color: #212121; line-height: 150%; font-family: Verdana">OOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">的延续，是</span><span style="color: #212121; line-height: 150%; font-family: Verdana">Aspect Oriented Programming</span><span style="color: #212121; line-height: 150%; font-family: 宋体">的缩写，意思是面向方面编程。</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">实际是</span><span style="color: #212121; line-height: 150%; font-family: Verdana">GoF</span><span style="color: #212121; line-height: 150%; font-family: 宋体">设计模式的延续，设计模式孜孜不倦追求的是调用者和被调用者之间的解耦，</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">可以说也是这种目标的一种实现。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　举例：假设有在一个应用系统中，有一个共享的数据必须被并发同时访问，首先，将这个数据封装在数据对象中，称为</span><span style="color: #212121; line-height: 150%; font-family: Verdana">Data Class</span><span style="color: #212121; line-height: 150%; font-family: 宋体">，同时，将有多个访问类，专门用于在同一时刻访问这同一个数据对象。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　为了完成上述并发访问同一资源的功能，需要引入锁</span><span style="color: #212121; line-height: 150%; font-family: Verdana">Lock</span><span style="color: #212121; line-height: 150%; font-family: 宋体">的概念，也就是说，某个时刻，当有一个访问类访问这个数据对象时，这个数据对象必须上锁</span><span style="color: #212121; line-height: 150%; font-family: Verdana">Locked</span><span style="color: #212121; line-height: 150%; font-family: 宋体">，用完后就立即解锁</span><span style="color: #212121; line-height: 150%; font-family: Verdana">unLocked</span><span style="color: #212121; line-height: 150%; font-family: 宋体">，再供其它访问类访问。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　使用传统的编程习惯，我们会创建一个抽象类，所有的访问类继承这个抽象父类，如下：</span></p>
<div align="center">
<table style="width: 80%" cellspacing="0" cellpadding="0" width="80%" border="0">
    <tbody>
        <tr>
            <td style="padding-right: 0cm; padding-left: 0cm; background: #cccccc; padding-bottom: 0cm; padding-top: 0cm">
            <p style="text-align: left" align="left"><span style="font-size: 9pt; color: black; font-family: Verdana">abstract class Worker{</span></p>
            <p style="text-align: left" align="left"><span style="font-size: 9pt; color: black; font-family: 宋体">　　</span><span style="font-size: 9pt; color: black; font-family: Verdana">abstract void locked();<br />
            </span><span style="font-size: 9pt; color: black; font-family: 宋体">　　</span><span style="font-size: 9pt; color: black; font-family: Verdana">abstract void accessDataObject();<br />
            </span><span style="font-size: 9pt; color: black; font-family: 宋体">　　</span><span style="font-size: 9pt; color: black; font-family: Verdana">abstract void unlocked();</span></p>
            <p style="text-align: left" align="left"><span style="font-size: 9pt; color: black; font-family: Verdana">}</span></p>
            </td>
        </tr>
    </tbody>
</table>
</div>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　　缺点：</span></p>
<ul type="square">
    <li style="color: black; line-height: 150%; text-align: left; tab-stops: list 36.0pt"><span style="line-height: 150%; font-family: Verdana">accessDataObject()</span><span style="line-height: 150%; font-family: 宋体">方法需要有</span><span style="line-height: 150%; font-family: Verdana">&#8220;</span><span style="line-height: 150%; font-family: 宋体">锁</span><span style="line-height: 150%; font-family: Verdana">&#8221;</span><span style="line-height: 150%; font-family: 宋体">状态之类的相关代码。</span></li>
    <li style="color: black; line-height: 150%; text-align: left; tab-stops: list 36.0pt"><span style="line-height: 150%; font-family: Verdana">Java</span><span style="line-height: 150%; font-family: 宋体">只提供了单继承，因此具体访问类只能继承这个父类，如果具体访问类还要继承其它父类，比如另外一个如</span><span style="line-height: 150%; font-family: Verdana">Worker</span><span style="line-height: 150%; font-family: 宋体">的父类，将无法方便实现。</span></li>
    <li style="color: black; line-height: 150%; text-align: left; tab-stops: list 36.0pt"><span style="line-height: 150%; font-family: 宋体">重用被打折扣，具体访问类因为也包含</span><span style="line-height: 150%; font-family: Verdana">&#8220;</span><span style="line-height: 150%; font-family: 宋体">锁</span><span style="line-height: 150%; font-family: Verdana">&#8221;</span><span style="line-height: 150%; font-family: 宋体">状态之类的相关代码，只能被重用在相关有</span><span style="line-height: 150%; font-family: Verdana">&#8220;</span><span style="line-height: 150%; font-family: 宋体">锁</span><span style="line-height: 150%; font-family: Verdana">&#8221;</span><span style="line-height: 150%; font-family: 宋体">的场合，重用范围很窄。</span><span style="line-height: 150%; font-family: Verdana"><br />
    <br />
    </span><span style="line-height: 150%; font-family: 宋体">仔细研究这个应用的</span><span style="line-height: 150%; font-family: Verdana">&#8220;</span><span style="line-height: 150%; font-family: 宋体">锁</span><span style="line-height: 150%; font-family: Verdana">&#8221;</span><span style="line-height: 150%; font-family: 宋体">，它其实有下列特性：</span></li>
    <li style="color: black; line-height: 150%; text-align: left; tab-stops: list 36.0pt"><span style="line-height: 150%; font-family: Verdana">&#8220;</span><span style="line-height: 150%; font-family: 宋体">锁</span><span style="line-height: 150%; font-family: Verdana">&#8221;</span><span style="line-height: 150%; font-family: 宋体">功能不是具体访问类的首要或主要功能，访问类主要功能是访问数据对象，例如读取数据或更改动作。</span></li>
    <li style="color: black; line-height: 150%; text-align: left; tab-stops: list 36.0pt"><span style="line-height: 150%; font-family: Verdana">&#8220;</span><span style="line-height: 150%; font-family: 宋体">锁</span><span style="line-height: 150%; font-family: Verdana">&#8221;</span><span style="line-height: 150%; font-family: 宋体">行为其实是和具体访问类的主要功能可以独立、区分开来的。</span></li>
    <li style="color: black; line-height: 150%; text-align: left; tab-stops: list 36.0pt"><span style="line-height: 150%; font-family: Verdana">&#8220;</span><span style="line-height: 150%; font-family: 宋体">锁</span><span style="line-height: 150%; font-family: Verdana">&#8221;</span><span style="line-height: 150%; font-family: 宋体">功能其实是这个系统的一个纵向切面，涉及许多类、许多类的方法。如下图：</span><span style="line-height: 150%; font-family: Verdana"><br />
    </span></li>
</ul>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　因此<img height="258" alt="" src="http://www.blogjava.net/images/blogjava_net/msmary/lock.png" width="250" border="0" />，一个新的程序结构应该是关注系统的纵向切面，例如这个应用的</span><span style="color: #212121; line-height: 150%; font-family: Verdana">&#8220;</span><span style="color: #212121; line-height: 150%; font-family: 宋体">锁</span><span style="color: #212121; line-height: 150%; font-family: Verdana">&#8221;</span><span style="color: #212121; line-height: 150%; font-family: 宋体">功能，这个新的程序结构就是</span><span style="color: #212121; line-height: 150%; font-family: Verdana">aspect</span><span style="color: #212121; line-height: 150%; font-family: 宋体">（方面）</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　在这个应用中，</span><span style="color: #212121; line-height: 150%; font-family: Verdana">&#8220;</span><span style="color: #212121; line-height: 150%; font-family: 宋体">锁</span><span style="color: #212121; line-height: 150%; font-family: Verdana">&#8221;</span><span style="color: #212121; line-height: 150%; font-family: 宋体">方面（</span><span style="color: #212121; line-height: 150%; font-family: Verdana">aspect</span><span style="color: #212121; line-height: 150%; font-family: 宋体">）应该有以下职责：</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　提供一些必备的功能，对被访问对象实现加锁或解锁功能。以保证所有在修改数据对象的操作之前能够调用</span><span style="color: #212121; line-height: 150%; font-family: Verdana">lock()</span><span style="color: #212121; line-height: 150%; font-family: 宋体">加锁，在它使用完成后，调用</span><span style="color: #212121; line-height: 150%; font-family: Verdana">unlock()</span><span style="color: #212121; line-height: 150%; font-family: 宋体">解锁。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><strong><span style="color: #212121; font-family: Verdana">AOP</span></strong><strong><span style="color: #212121; font-family: 宋体">应用范围</span></strong><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<br />
</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　　很明显，</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">非常适合开发</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">容器服务器，目前</span><span style="color: #212121; line-height: 150%; font-family: Verdana">JBoss 4.0</span><span style="color: #212121; line-height: 150%; font-family: 宋体">正是使用</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">框架进行开发。</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　　具体功能如下：</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Authentication </span><span style="color: #212121; line-height: 150%; font-family: 宋体">权限</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Caching </span><span style="color: #212121; line-height: 150%; font-family: 宋体">缓存</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Context passing </span><span style="color: #212121; line-height: 150%; font-family: 宋体">内容传递</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Error handling </span><span style="color: #212121; line-height: 150%; font-family: 宋体">错误处理</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Lazy loading</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　懒加载</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Debugging</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　　调试</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
logging, tracing, profiling and monitoring</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　记录跟踪　优化　校准</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Performance optimization</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　性能优化</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Persistence</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　　持久化</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Resource pooling</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　资源池</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Synchronization</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　同步</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
Transactions </span><span style="color: #212121; line-height: 150%; font-family: 宋体">事务</span></p>
<p style="line-height: 150%; text-align: left" align="left"><strong><span style="color: #212121; font-family: Verdana">AOP</span></strong><strong><span style="color: #212121; font-family: 宋体">有必要吗？</span></strong></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　当然，上述应用范例在没有使用</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">情况下，也得到了解决，例如</span><span style="color: #212121; line-height: 150%; font-family: Verdana">JBoss 3.XXX</span><span style="color: #212121; line-height: 150%; font-family: 宋体">也提供了上述应用功能，但是没有使用</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　但是，使用</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">可以让我们从一个更高的抽象概念来理解软件系统，</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">也许提供一种有价值的工具。可以这么说：因为使用</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">结构，现在</span><span style="color: #212121; line-height: 150%; font-family: Verdana">JBoss 4.0</span><span style="color: #212121; line-height: 150%; font-family: 宋体">的源码要比</span><span style="color: #212121; line-height: 150%; font-family: Verdana">JBoss 3.X</span><span style="color: #212121; line-height: 150%; font-family: 宋体">容易理解多了，这对于一个大型复杂系统来说是非常重要的。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　从另外一个方面说，好像不是所有的人都需要关心</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">，它可能是一种架构设计的选择，如果选择</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">系统，</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">关注的上述通用方面都已经被</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">容器实现了，</span><span style="color: #212121; line-height: 150%; font-family: Verdana">J2EE</span><span style="color: #212121; line-height: 150%; font-family: 宋体">应用系统开发者可能需要更多地关注行业应用方面</span><span style="color: #212121; line-height: 150%; font-family: Verdana">aspect</span><span style="color: #212121; line-height: 150%; font-family: 宋体">。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
</span><strong><span style="color: #212121; font-family: Verdana">AOP</span></strong><strong><span style="color: #212121; font-family: 宋体">具体实现</span></strong></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">是一个概念，并没有设定具体语言的实现，它能克服那些只有单继承特性语言的缺点（如</span><span style="color: #212121; line-height: 150%; font-family: Verdana">Java</span><span style="color: #212121; line-height: 150%; font-family: 宋体">），目前</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">具体实现有以下几个项目：</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AspectJ (TM)</span><span style="color: #212121; line-height: 150%; font-family: 宋体">：　创建于</span><span style="color: #212121; line-height: 150%; font-family: Verdana">Xerox PARC. </span><span style="color: #212121; line-height: 150%; font-family: 宋体">有近十年历史，成熟</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　　缺点：过于复杂；破坏封装；需要专门的</span><span style="color: #212121; line-height: 150%; font-family: Verdana">Java</span><span style="color: #212121; line-height: 150%; font-family: 宋体">编译器。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">　　动态</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">：使用</span><span style="color: #212121; line-height: 150%; font-family: Verdana">JDK</span><span style="color: #212121; line-height: 150%; font-family: 宋体">的动态代理</span><span style="color: #212121; line-height: 150%; font-family: Verdana">API</span><span style="color: #212121; line-height: 150%; font-family: 宋体">或字节码</span><span style="color: #212121; line-height: 150%; font-family: Verdana">Bytecode</span><span style="color: #212121; line-height: 150%; font-family: 宋体">处理技术。</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<br />
</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　　基于动态代理</span><span style="color: #212121; line-height: 150%; font-family: Verdana">API</span><span style="color: #212121; line-height: 150%; font-family: 宋体">的具体项目有：</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<a href="http://www.jboss.org/index.html?module=html&amp;op=userdisplay&amp;id=developers/pro" target="_blank"><span style="color: #003366; line-height: 150%; font-family: 宋体; text-decoration: none; text-underline: none">　　</span><span style="color: #003366; line-height: 150%; text-decoration: none; text-underline: none">JBoss 4.0</span></a> JBoss 4.0</span><span style="color: #212121; line-height: 150%; font-family: 宋体">服务器</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<a href="http://nanning.sourceforge.net/" target="_blank"><span style="color: #003366; line-height: 150%; font-family: 宋体; text-decoration: none; text-underline: none">　　</span><span style="color: #003366; line-height: 150%; text-decoration: none; text-underline: none">nanning</span></a></span><span style="color: #212121; line-height: 150%; font-family: 宋体">　这是以中国南宁命名的一个项目，搞不清楚为什么和中国相关？是中国人发起的？</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<br />
</span><span style="color: #212121; line-height: 150%; font-family: 宋体">　　基于字节码的项目有：</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<a href="http://aspectwerkz.codehaus.org/" target="_blank"><span style="color: #003366; line-height: 150%; font-family: 宋体; text-decoration: none; text-underline: none">　　</span><span style="color: #003366; line-height: 150%; text-decoration: none; text-underline: none">aspectwerkz</span></a></span><span style="color: #212121; line-height: 150%; font-family: 宋体">　</span><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<a href="http://springframework.org/" target="_blank"><span style="color: #003366; line-height: 150%; font-family: 宋体; text-decoration: none; text-underline: none">　　</span><span style="color: #003366; line-height: 150%; text-decoration: none; text-underline: none">spring</span><span style="color: #003366; line-height: 150%; font-family: 宋体; text-decoration: none; text-underline: none">　？</span></a></span></p>
<p style="line-height: 150%; text-align: left" align="left"><span style="color: #212121; line-height: 150%; font-family: 宋体">在以后其它文章中，我将继续对</span><span style="color: #212121; line-height: 150%; font-family: Verdana">AOP</span><span style="color: #212121; line-height: 150%; font-family: 宋体">概念进行分析，和大家一起学习进步。</span></p>
<p style="line-height: 150%; text-align: left" align="left"><strong><span style="color: #212121; font-family: 宋体">参考资料：</span></strong><span style="color: #212121; line-height: 150%; font-family: Verdana"><br />
<a href="http://www.voelter.de/data/articles/aop/aop.html" target="_blank"><span style="color: #003366; line-height: 150%; text-decoration: none; text-underline: none">http://www.voelter.de/data/articles/aop/aop.html</span></a><br />
<a href="http://www.ociweb.com/javasig/knowledgebase/2003-12/Aspect-Oriented_Java_Development.pdf" target="_blank"><span style="color: #003366; line-height: 150%; text-decoration: none; text-underline: none">Aspect-Oriented_Java_Development.pdf</span></a></span></p>
<img src ="http://www.blogjava.net/msmary/aggbug/155418.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/msmary/" target="_blank">谭明</a> 2007-10-23 22:55 <a href="http://www.blogjava.net/msmary/articles/155418.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>J2EE架构数据表示：Struts＋Hibernate </title><link>http://www.blogjava.net/msmary/articles/153410.html</link><dc:creator>谭明</dc:creator><author>谭明</author><pubDate>Tue, 16 Oct 2007 16:07:00 GMT</pubDate><guid>http://www.blogjava.net/msmary/articles/153410.html</guid><wfw:comment>http://www.blogjava.net/msmary/comments/153410.html</wfw:comment><comments>http://www.blogjava.net/msmary/articles/153410.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/msmary/comments/commentRss/153410.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/msmary/services/trackbacks/153410.html</trackback:ping><description><![CDATA[<span class="a14c" id="zoom">&nbsp;
<p style="text-indent: 2em">在struts+hibernate这种结构中，是不应该把Hibernate产生的PO直接传递给JSP的，不管他是Iterator，还是List，这是一个设计错误。
<p style="text-indent: 2em">我来谈谈在J2EE架构中各层的数据表示方法：
<p style="text-indent: 2em">◆Web层的数据表示是FormBean，数据来源于HTML Form POST
<p style="text-indent: 2em">◆业务层的数据表示是VO
<p style="text-indent: 2em">◆持久层的数据表示是PO，其数据来源于数据库，持久层的数据表示例如CMP
<p style="text-indent: 2em">在一个规范的J2EE架构中，不同层的数据表示应该被限制在层内，而不应该扩散到其它层，这样可以降低层间的耦合性，提高J2EE架构整体的可维护性和可扩展性。比如说Web层的逻辑进行了修改，那么只需要修改FormBean的结构，而不需要触动业务层和持久层的代码修改。同样的，当数据库表进行了小的调整，那么也只需要修改持久层数据表示，而不需要触动业务层代码和Web层代码。
<p style="text-indent: 2em">不过由于Hibernate的强大功能，例如动态生成PO，PO的状态管理可以脱离Session，使得在应用了Hibernate的J2EE框架中，PO完全可以充当VO，因此我们下面把PO和VO合并，统称为PO。
<p style="text-indent: 2em">先来谈谈ActionFormBean和持久层的PO之间的重大区别：
<p style="text-indent: 2em">在简单的应用中，ActionFormBean和PO几乎是没有区别，所以很多人干脆就是用ActionFormBean来充当PO，于是ActionFormBean从JSP页面到Servlet控制层再到业务层，然后穿过持久层，最后一直映射到数据库表。真是一竿子捅到了底！
<p style="text-indent: 2em">但是在复杂的应用中，ActionFormBean和PO是分离的，他们也不可能一样。ActionFormBean是和网页里面的Form表单一一对应的，Form里面有什么元素，Bean里面就有什么属性。而PO和数据库表对应，因此如果数据库表不修改，那么PO也不会修改，如果页面的流程和数据库表字段对应关系不一致，那么你又如何能够使用ActionFormBean来取代PO呢？
<p style="text-indent: 2em">比如说吧，用户注册页面要求注册用户的基本信息，因此HTML Form里面包含了基本信息属性，于是你需要一个ActionFormBean来一一对应(注意：是一一对应)，每个Bean属性对应一个文本框或者选择框什么的。
<p style="text-indent: 2em">而用户这个持久对象呢？他的属性和ActionFormBean有什么明显不同呢？他会有一些ActionFormBean所没有的集合属性，比如说用户的权限属性，用户的组属性，用户的帖子等等。另外还有可能的是在ActionFormBean里面有3个属性，分别是用户的First Name, Middle Name, Last Name，而在我的User这个持久对象中就是一个Name对象属性。
<p style="text-indent: 2em">假设我的注册页面原来只要你提供First Name，那么ActionFormBean就这一个属性，后来我要你提供全名，你要改ActionFormBean，加两个属性。但是这个时候PO是不应该修改滴，因为数据库没有改。
<p style="text-indent: 2em">那么在一个完整的J2EE系统中应该如何进行合理的设计呢？
<p style="text-indent: 2em">JSP(View) ---&gt; Action Form Bean (Module) ---&gt; Action(Control)
<p style="text-indent: 2em">Action Form Bean是Web层的数据表示，它和HTML页面Form对应，只要Web页面的操作流程发生改变，它就要相应的进行修改，它不应该也不能被传递到业务层和持久层，否则一旦页面修改，会一直牵连到业务层和持久层的大面积的代码进行修改，对于软件的可维护性和可扩展性而言，是一个灾难，Actiont就是他的边界，到此为止！
<p style="text-indent: 2em">Action(Web Control) ---&gt; Business Bean ---&gt; DAO ---&gt; ORM ---&gt;DB
<p style="text-indent: 2em">而PO则是业务层和持久层的数据表示，它在业务层和持久层之间进行流动，他不应该也不能被传递到Web层的View中去，而ActionServlet就是他的边界，到此为止！
<p style="text-indent: 2em">然后来看一看整个架构的流程：
<p style="text-indent: 2em">当用户通过浏览器访问网页，提交了一个页面。于是Action拿到了这个FormBean，他会把FormBean属性读出来，然后构造一个PO对象，再调用业务层的Bean类，完成了注册操作，重定向到成功页面。而业务层Bean收到这个PO对象之后，调用DAO接口方法，进行持久对象的持久化操作。
<p style="text-indent: 2em">当用户查询某个会员的信息的时候，他用全名进行查询，于是Action得到一个UserNameFormBean包括了3个属性，分别是first name, middle name, last name，然后Action把UserNameFormBean的3个属性读出来，构造Name对象，再调用业务Bean，把Name对象传递给业务Bean，进行查询。
<p style="text-indent: 2em">业务Bean取得Name(注意:Name对象只是User的一个属性)对象之后调用DAO接口，返回一个User的PO对象，注意这个User不同于在Web层使用的UserFormBean，他有很多集合属性的。然后业务Bean把User对象返回给Action。
<p style="text-indent: 2em">Action拿到User之后，把User的基本属性取出(集合属性如果不需要就免了)，构造UserFormBean，然后把UserFormBean request.setAttribute(...)，然后重定向到查询结果页面。
<p style="text-indent: 2em">查询页面拿到request对象里面的ActionFormBean，自动调用tag显示之。
<p style="text-indent: 2em">总结：
<p style="text-indent: 2em">Form Bean是Web层的数据表示，他不能被传递到业务层；PO是持久层的数据表示，在特定情况下，例如Hibernate中，他可以取代VO出现在业务层，但是不管PO还是VO都必须限制在业务层内使用，最多到达Web层的Control，绝不能被扩散到View去。
<p style="text-indent: 2em">Form Bean和PO之间的数据转化是在Action中进行的。
<p style="text-indent: 2em">BTW（顺便说一句）：
<p style="text-indent: 2em">JDO1.x还不能像Hibernate功能这样强大，PO不能脱离持久层，所以必须在业务层使用VO，因此必须在业务层进行大量的VO和PO的转化操作，相对于Hibernate来说，编程比较烦琐。
<p style="text-indent: 2em">当然了，理论是一回事，实际操作也不一定非要这样干，你可以自行取舍，在实际项目中灵活一点，增加一点bad smell，提高开发效率。只不过在大型项目中最好还是严丝合缝，不然的话，改版的时候会痛苦的很的。 </p>
</span>
<img src ="http://www.blogjava.net/msmary/aggbug/153410.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/msmary/" target="_blank">谭明</a> 2007-10-17 00:07 <a href="http://www.blogjava.net/msmary/articles/153410.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>J2EE 全面简介(转)</title><link>http://www.blogjava.net/msmary/articles/152154.html</link><dc:creator>谭明</dc:creator><author>谭明</author><pubDate>Thu, 11 Oct 2007 13:33:00 GMT</pubDate><guid>http://www.blogjava.net/msmary/articles/152154.html</guid><wfw:comment>http://www.blogjava.net/msmary/comments/152154.html</wfw:comment><comments>http://www.blogjava.net/msmary/articles/152154.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/msmary/comments/commentRss/152154.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/msmary/services/trackbacks/152154.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 本文从五个方面对J2EE进行了比较全面的介绍。从J2EE的概念说起，到它的优势，到J2EE典型的四层模型，和它的框架结构，最后是J2EE十三种核心技术的一个简介。本文分门别类的对J2EE中的服务，组件，层次，容器，API都做了比较详细的介绍，相信看完此文，读者会对J2EE有一个更清晰的认识。<br />
<br />
一. J2EE的概念<br />
目前，Java 2平台有3个版本，它们是适用于小型设备和智能卡的Java 2平台Micro版（Java 2 Platform Micro Edition，J2ME）、适用于桌面系统的Java 2平台标准版（Java 2 Platform Standard Edition，J2SE）、适用于创建服务器应用程序和服务的Java2平台企业版（Java 2 Platform Enterprise Edition，J2EE）。<br />
J2EE是一种利用Java 2平台来简化企业解决方案的开发、部署和管理相关的复杂问题的体系结构。J2EE技术的基础就是核心Java平台或Java 2平台的标准版，J2EE不仅巩固了标准版中的许多优点，例如"编写一次、随处运行"的特性、方便存取数据库的JDBC API、CORBA技术以及能够在Internet应用中保护数据的安全模式等等，同时还提供了对 EJB（Enterprise JavaBeans）、Java Servlets API、JSP（Java Server Pages）以及XML技术的全面支持。其最终目的就是成为一个能够使企业开发者大幅缩短投放市场时间的<br />
体系结构。<br />
J2EE体系结构提供中间层集成框架用来满足无需太多费用而又需要高可用性、高可靠性以及可扩展性的应用的需求。通过提供统一的开发平台，J2EE降低了开发多层应用的费用和复杂性，同时提供对现有应用程序集成强有力支持，完全支持Enterprise JavaBeans，有良好的向导支持打包和部署应用，添加目录支持，增强了安全机制，提高了性能。<br />
<br />
二. J2EE的优势<br />
J2EE为搭建具有可伸缩性、灵活性、易维护性的商务系统提供了良好的机制:<br />
保留现存的IT资产: 由于企业必须适应新的商业需求，利用已有的企业信息系统方面的投资，而不是重新制定全盘方案就变得很重要。这样，一个以渐进的（而不是激进的，全盘否定的）方式建立在已有系统之上的服务器端平台机制是公司所需求的。J2EE架构可以充分利用用户原有的投资，如一些公司使用的BEA Tuxedo、IBM CICS, IBM Encina,、Inprise VisiBroker 以及Netscape Application Server。这之所以成为可能是因为J2EE拥有广泛的业界支持和一些重要的'企业计算'领域供应商的参与。每一个供应商都对现有的客户提供了不用废弃已有投资，进入可移植的J2EE领域的升级途径。由于基于J2EE平台的产品几乎能够在任何操作系统和硬件配置上运行，现有的操作系统和硬件也<br />
能被保留使用。<br />
高效的开发: J2EE允许公司把一些通用的、很繁琐的服务端任务交给中间件供应商去完成。这样开发人员可以集中精力在如何创建商业逻辑上，相应地缩短了开发时间。高级中间件供应商提供以下这些复杂的中间件服务:<br />
状态管理服务 -- 让开发人员写更少的代码，不用关心如何管理状态，这样能够更快地完成程序开发。<br />
持续性服务 -- 让开发人员不用对数据访问逻辑进行编码就能编写应用程序，能生成更<br />
轻巧，与数据库无关的应用程序，这种应用程序更易于开发与维护。<br />
分布式共享数据对象CACHE服务 -- 让开发人员编制高性能的系统，极大提高整体部署的<br />
伸缩性。<br />
支持异构环境: J2EE能够开发部署在异构环境中的可移植程序。基于J2EE的应用程序不<br />
依赖任何特定操作系统、中间件、硬件。因此设计合理的基于J2EE的程序只需开发一次<br />
就可部署到各种平台。这在典型的异构企业计算环境中是十分关键的。J2EE标准也允许<br />
客户订购与J2EE兼容的第三方的现成的组件，把他们部署到异构环境中，节省了由自己<br />
制订整个方案所需的费用。<br />
可伸缩性: 企业必须要选择一种服务器端平台，这种平台应能提供极佳的可伸缩性去满足那些在他们系统上进行商业运作的大批新客户。基于J2EE平台的应用程序可被部署到各种操作系统上。例如可被部署到高端UNIX与大型机系统，这种系统单机可支持64至256个处理器。（这是NT服务器所望尘莫及的）J2EE领域的供应商提供了更为广泛的负载平衡策略。能消除系统中的瓶颈，允许多台服务器集成部署。这种部署可达数千个处理器，实现可高度伸缩的系统，满足未来商业应用的需要。<br />
稳定的可用性: 一个服务器端平台必须能全天候运转以满足公司客户、合作伙伴的需要。因为INTERNET是全球化的、无处不在的，即使在夜间按计划停机也可能造成严重损失。若是意外停机，那会有灾难性后果。J2EE部署到可靠的操作环境中，他们支持长期的可用性。一些J2EE部署在WINDOWS环境中，客户也可选择健壮性能更好的操作系统如Sun Solaris、IBM OS/390。最健壮的操作系统可达到99.999%的可用性或每年只需5分钟停机时间。这是实时性很强商业系统理想的选择。<br />
<br />
<br />
三. J2EE 的四层模型<br />
J2EE使用多层的分布式应用模型，应用逻辑按功能划分为组件，各个应用组件根据他们<br />
所在的层分布在不同的机器上。事实上，sun设计J2EE的初衷正是为了解决两层模式(cl<br />
ient/server)的弊端，在传统模式中，客户端担当了过多的角色而显得臃肿，在这种模<br />
式中，第一次部署的时候比较容易，但难于升级或改进，可伸展性也不理想，而且经常<br />
基于某种专有的协议――通常是某种数据库协议。它使得重用业务逻辑和界面逻辑非常<br />
困难。现在J2EE 的多层企业级应用模型将两层化模型中的不同层面切分成许多层。一个<br />
多层化应用能够为不同的每种服务提供一个独立的层，以下是 J2EE 典型的四层结构:<br />
运行在客户端机器上的客户层组件<br />
运行在J2EE服务器上的Web层组件<br />
运行在J2EE服务器上的业务逻辑层组件<br />
运行在EIS服务器上的企业信息系统(Enterprise information system)层软件<br />
J2EE应用程序组件<br />
J2EE应用程序是由组件构成的.J2EE组件是具有独立功能的软件单元，它们通过相关的类<br />
和文件组装成J2EE应用程序，并与其他组件交互。J2EE说明书中定义了以下的J2EE组件<br />
:<br />
应用客户端程序和applets是客户层组件.<br />
Java Servlet和JavaServer Pages(JSP)是web层组件.<br />
Enterprise JavaBeans(EJB)是业务层组件.<br />
客户层组件<br />
J2EE应用程序可以是基于web方式的,也可以是基于传统方式的.<br />
web 层组件J2EE web层组件可以是JSP 页面或Servlets.按照J2EE规范，静态的HTML页面<br />
<br />
<br />
和Applets不算是web层组件。<br />
正如下图所示的客户层那样，web层可能包含某些 JavaBean 对象来处理用户输入，并把<br />
输入发送给运行在业务层上的enterprise bean 来进行处理。<br />
业务层组件<br />
业务层代码的逻辑用来满足银行，零售，金融等特殊商务领域的需要,由运行在业务层上<br />
的enterprise bean 进行处理. 下图表明了一个enterprise bean 是如何从客户端程序<br />
接收数据，进行处理(如果必要的话), 并发送到EIS 层储存的，这个过程也可以逆向进<br />
行。<br />
有三种企业级的bean: 会话(session) beans, 实体(entity) beans, 和 消息驱动(mes<br />
sage-driven) beans. 会话bean 表示与客户端程序的临时交互. 当客户端程序执行完后<br />
, 会话bean 和相关数据就会消失. 相反, 实体bean 表示数据库的表中一行永久的记录<br />
. 当客户端程序中止或服务器关闭时, 就会有潜在的服务保证实体bean 的数据得以保存<br />
.消息驱动 bean 结合了会话bean 和 JMS的消息监听器的特性, 允许一个业务层组件异<br />
步接收JMS 消息.<br />
企业信息系统层<br />
企业信息系统层处理企业信息系统软件包括企业基础建设系统例如企业资源计划 (ERP)<br />
, 大型机事务处理, 数据库系统,和其它的遗留信息系统. 例如，J2EE 应用组件可能为<br />
了数据库连接需要访问企业信息系统<br />
四. J2EE 的结构<br />
这种基于组件，具有平台无关性的J2EE 结构使得J2EE 程序的编写十分简单，因为业务<br />
逻辑被封装成可复用的组件，并且J2EE 服务器以容器的形式为所有的组件类型提供后台<br />
服务. 因为你不用自己开发这种服务, 所以你可以集中精力解决手头的业务问题.<br />
<br />
<br />
容器和服务<br />
容器设置定制了J2EE服务器所提供得内在支持，包括安全，事务管理，JNDI(Java Nami<br />
ng and Directory Interface)寻址,远程连接等服务，以下列出最重要的几种服务：<br />
J2EE安全(Security)模型可以让你配置 web 组件或enterprise bean ,这样只有被授权<br />
的用户才能访问系统资源. 每一客户属于一个特别的角色，而每个角色只允许激活特定<br />
的方法。你应在enterprise bean的布置描述中声明角色和可被激活的方法。由于这种声<br />
明性的方法，你不必编写加强安全性的规则。<br />
J2EE 事务管理（Transaction Management）模型让你指定组成一个事务中所有方法间的<br />
关系，这样一个事务中的所有方法被当成一个单一的单元. 当客户端激活一个enterpri<br />
se bean中的方法，容器介入一管理事务。因有容器管理事务，在enterprise bean中不<br />
必对事务的边界进行编码。要求控制分布式事务的代码会非常复杂。你只需在布置描述<br />
文件中声明enterprise bean的事务属性，而不用编写并调试复杂的代码。容器将读此文<br />
件并为你处理此enterprise bean的事务。<br />
JNDI 寻址(JNDI Lookup)服务向企业内的多重名字和目录服务提供了一个统一的接口,这<br />
样应用程序组件可以访问名字和目录服务.<br />
J2EE远程连接（Remote Client Connectivity）模型管理客户端和enterprise bean间的<br />
低层交互. 当一个enterprise bean创建后, 一个客户端可以调用它的方法就象它和客户<br />
端位于同一虚拟机上一样.<br />
生存周期管理（Life Cycle Management）模型管理enterprise bean的创建和移除,一个<br />
enterprise bean在其生存周期中将会历经几种状态。容器创建enterprise bean，并在<br />
可用实例池与活动状态中移动他，而最终将其从容器中移除。即使可以调用enterprise<br />
bean的create及remove方法，容器也将会在后台执行这些任务。<br />
<br />
<br />
数据库连接池（Database Connection Pooling）模型是一个有价值的资源。获取数据库<br />
连接是一项耗时的工作，而且连接数非常有限。容器通过管理连接池来缓和这些问题。<br />
enterprise bean可从池中迅速获取连接。在bean释放连接之可为其他bean使用。<br />
容器类型<br />
J2EE应用组件可以安装部署到以下几种容器中去:<br />
EJB 容器管理所有J2EE 应用程序中企业级bean 的执行. enterprise bean 和它们的容<br />
器运行在J2EE 服务器上.<br />
Web 容器管理所有J2EE 应用程序中JSP页面和Servlet组件的执行. Web 组件和它们的容<br />
器运行在J2EE 服务器上.<br />
应用程序客户端容器管理所有J2EE应用程序中应用程序客户端组件的执行. 应用程序客<br />
户端和它们的容器运行在J2EE 服务器上.<br />
Applet 容器是运行在客户端机器上的web浏览器和 Java 插件的结合.<br />
五. J2EE的核心API与组件<br />
J2EE平台由一整套服务（Services）、应用程序接口（APIs）和协议构成，它对开发基<br />
于Web的多层应用提供了功能支持，下面对J2EE中的13种技术规范进行简单的描述(限于<br />
篇幅，这里只能进行简单的描述):<br />
JDBC(Java Database Connectivity):<br />
JDBC API为访问不同的数据库提供了一种统一的途径，象ODBC一样，JDBC对开发者屏蔽<br />
了一些细节问题，另外，JDCB对数据库的访问也具有平台无关性。<br />
JNDI(Java Name and Directory Interface):<br />
JNDI API被用于执行名字和目录服务。它提供了一致的模型来存取和操作企业级的资源<br />
如DNS和LDAP，本地文件系统，或应用服务器中的对象。<br />
<br />
<br />
EJB(Enterprise JavaBean):<br />
J2EE技术之所以赢得某体广泛重视的原因之一就是EJB。它们提供了一个框架来开发和实<br />
施分布式商务逻辑，由此很显著地简化了具有可伸缩性和高度复杂的企业级应用的开发<br />
。EJB规范定义了EJB组件在何时如何与它们的容器进行交互作用。容器负责提供公用的<br />
服务，例如目录服务、事务管理、安全性、资源缓冲池以及容错性。但这里值得注意的<br />
是，EJB并不是实现J2EE的唯一途径。正是由于J2EE的开放性，使得有的厂商能够以一种<br />
和EJB平行的方式来达到同样的目的。<br />
RMI(Remote Method Invoke):<br />
正如其名字所表示的那样，RMI协议调用远程对象上方法。它使用了序列化方式在客户端<br />
和服务器端传递数据。RMI是一种被EJB使用的更底层的协议。<br />
Java IDL/CORBA:<br />
在Java IDL的支持下，开发人员可以将Java和CORBA集成在一起。 他们可以创建Java对<br />
象并使之可在CORBA ORB中展开, 或者他们还可以创建Java类并作为和其它ORB一起展开<br />
的CORBA对象的客户。后一种方法提供了另外一种途径，通过它Java可以被用于将你的新<br />
的应用和旧的系统相集成。<br />
JSP(Java Server Pages):<br />
JSP页面由HTML代码和嵌入其中的Java代码所组成。服务器在页面被客户端所请求以后对<br />
这些Java代码进行处理，然后将生成的HTML页面返回给客户端的浏览器。<br />
Java Servlet:<br />
Servlet是一种小型的Java程序，它扩展了Web服务器的功能。作为一种服务器端的应用<br />
，当被请求时开始执行，这和CGI Perl脚本很相似。Servlet提供的功能大多与JSP类似<br />
，不过实现的方式不同。JSP通常是大多数HTML代码中嵌入少量的Java代码，而servlets<br />
全部由Java写成并且生成HTML。<br />
XML(Extensible Markup Language):<br />
XML是一种可以用来定义其它标记语言的语言。它被用来在不同的商务过程中共享数据。<br />
XML的发展和Java是相互独立的，但是，它和Java具有的相同目标正是平台独立性。通过<br />
将Java和XML的组合，您可以得到一个完美的具有平台独立性的解决方案。<br />
JMS(Java Message Service):<br />
MS是用于和面向消息的中间件相互通信的应用程序接口(API)。它既支持点对点的域，有<br />
支持发布/订阅(publish/subscribe)类型的域，并且提供对下列类型的支持：经认可的<br />
消息传递,事务型消息的传递，一致性消息和具有持久性的订阅者支持。JMS还提供了另<br />
一种方式来对您的应用与旧的后台系统相集成。<br />
JTA(Java Transaction Architecture):<br />
JTA定义了一种标准的API，应用系统由此可以访问各种事务监控。<br />
JTS(Java Transaction Service):<br />
JTS是CORBA OTS事务监控的基本的实现。JTS规定了事务管理器的实现方式。该事务管理<br />
器是在高层支持Java Transaction API (JTA)规范，并且在较底层实现OMG OTS specif<br />
ication的Java映像。JTS事务管理器为应用服务器、资源管理器、独立的应用以及通信<br />
资源管理器提供了事务服务。<br />
JavaMail:<br />
JavaMail是用于存取邮件服务器的API，它提供了一套邮件服务器的抽象类。不仅支持S<br />
MTP服务器，也支持IMAP服务器。<br />
JTA(JavaBeans Activation Framework):<br />
JavaMail利用JAF来处理MIME编码的邮件附件。 <br />
<img src ="http://www.blogjava.net/msmary/aggbug/152154.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/msmary/" target="_blank">谭明</a> 2007-10-11 21:33 <a href="http://www.blogjava.net/msmary/articles/152154.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>