Enterprise JavaBean笔记:第一印象

Plux posted @ 2012年10月05日 13:46 in Default with tags java EJB , 1902 阅读

这篇文章只是对 EJB 起一个很初步的认识。

以前觉得,既然有了 JSP 和 Servlet ,基本分离了表现和逻辑,再加上 Filter 作为视图层的补充,Listener 为事件监听。已经是一个比较完善的架构了。EJB 要作为那一部分的补充而存在呢?

实际上,EJB 的存在应该是为了补充 Servlet 对拓展性不足而存在的。EJB 的存在,一个基本的修改的是,把两层结构 user -> Servlet ,修改为 user -> Servlet -> EJB。实际上,如果按照原来的设想,Servlet本身就可以作为一个 Stateless Session Bean,但由于 Servlet 实现的历史原因, Servlet 必须继承于 HttpServlet 类,并且带有 HTTP 的特征,作为视图层的 JSP 实际上是一个特殊化的 Servlet 。也就是说, Servlet 本来也是为单一业务(HTTP)而存在的,算是一个适配器。而客户端技术,却不仅仅只是 HTTP 和 HTML,因此,一个只为业务而生的逻辑层应运而生,即 EJB 。

在《Java EE 6 Tutorial》中对 EJB 的介绍:

You should consider using enterprise beans if your application has any of the following requirements.

  • The application must be scalable. To accommodate a growing number of users, you may need to distribute an application’s components acrossmultiplemachines. Not only can the enterprise beans of an application run on differentmachines, but also their locationwill
  • remain transparent to the clients.
  • Transactionsmust ensure data integrity. Enterprise beans support transactions, the mechanisms thatmanage the concurrent access of shared objects.
  • The application will have a variety of clients. With only a few lines of code, remote clients can easily locate enterprise beans. These clients can be thin, various, and numerous.

EJB 的拓展性,主要体现在 EJB 容器的对象缓存上。由于 EJB 的缓存,客户端(包括 Web 应用)可以很快地获取 EJB 对象。而其他特点,数据一致性、支持多客户端,都基于对象池的设计。

EJB 的类型分为 Session bean 和 Message Driven Bean。 Session Bean 中的无状态 Bean 就是缓存的主要对象。关于这方面的资料,可以参考《The Java EE 6 Tutorial》。

你猜 说:
Oct 13, 2012 07:17:16 PM

为什么是plux呢?

Avatar_small
Plux 说:
Nov 24, 2012 01:59:42 PM

@你猜: 看看http://plux.is-programmer.com/about就知道了~


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter