Java资源网

| JAVA基础 | 环境配置 | JDBC | 线程技术 | Socket编程 | JavaMail | JAVA与XML | 设计模式 | 技术新闻 | Java认证 | 程序人生 软件下载
| JSP&Servlet | Spring | Struts | Hibernate | JBuilder | Eclipse | WebService | EJB技术 | J2ME开发 | 应用服务器 | JXTA | Ajax
Articles search文章搜索
   关键字:
   类 别:
       
New download 最新下载
· [组件]HTML Parser 1.5
· [教程]WebSphere Studio应用教程
· [组件]JDom 1.0
· [工具]Junit3.8.1
· [教程]EJB编程及J2EE系统架构和设计
· [教程]EJB教程
· [教程]J2EE Tutorial中文版
· [教程]Java编程思想2(英文)
· [教程]java编程思想(完整版)
· [教程]Java网络编程
New articles 最新文章
· 设计移动 Web 服务
· 解析XML的时候完全忽略DTD
· 理解XML Schema XML Schema 初步
· 标签库的深入研究
· 提升JSP应用程序的七大绝招
· 如何使用JDOM对XML文件进行操作
· 处理XML字符串中特殊字符
· 利用Digester把XML转换成为Java对象
· 使用WebService 和RMI远程协作
· 使用Axis开发Web Service程序
Articles top 热门文章
· Eclipse基础--plugin插件安装(6644)
· eclipse+tomcat+lomboz的安装配置说明(4774)
· Java程序员就业前景(4584)
· Windows下JAVA环境变量的设置祥解(3788)
· Tomcat下JSP、Servlet和JavaBean环境的配置(3716)
· 使用links方式安装Eclipse插件(3698)
· 一个老程序员的心理话(3533)
· linux下jdk的安装与配置(3459)
· 初学者入门:Structs中基本配置入门(3334)
· Eclipse 运行命令行参数大全(3084)
您的位置:首页>>EJB技术>>什么时候用EJB ,什么时候不用EJB?
什么时候用EJB ,什么时候不用EJB?
2005-07-09   来源:CSDN  作者: yiboo
 

什么时候用EJB ,什么时候不用EJB?

参考 Enterprise JavaBeans 4

这篇文章 讲述了何时使用EJB,何时不用EJB,以及用哪些可以替代EJB!


1 When to Use EJBs
Here's a list of situations where EJBs are strong; we haven't distinguished between

different types of EJBs.

 


Single and multisystem business transactions

The ability to maintain transactional integrity for complex business entities is one of

an EJB's key strengths. EJBs aren't alone in providing straightforward transactional

control over a single data repository. However, EJBs shine where multiple resources

(relational databases, messaging systems, etc.) are involved because they allow

transactions to spread across as many different resources as you like, so long as the

resources support distributed transactions.

 


Distributed functionality

Business services often live on a remote server. For example, a business enterprise will

have many different systems, ranging in degrees of inflexibility and entrenchment. One of

these systems may need to access another; EJBs, which are inherently distributed, are

often the simplest way to distribute remote services. EJB also allows you to provide

business services to remote clients more easily than some alternatives. Remote access

through components is easier to maintain than direct database access, because the

component code can shield the client from database schema changes.

 


Portable components (not classes)

Until recently, if you wanted to share your business services with another application

developer, you were forced to share classes or at least packages. Java did not allow for

the easy creation of enterprise components, reusable software building blocks that can be

assembled with other components to form an application. EJBs allow you to package your

business logic into a tidy, distributable unit that can be shared in a loosely coupled

fashion. The user of your component need only tweak a descriptor file for her

environment.

 


Applications relying on asynchronous messaging

EJBs (specifically MDBs) provide a strong technology for handling asynchronous

communication such as JMS-based messaging or web services.

 


Security roles

If your application's business operations can be mapped to specific business roles in

your enterprise, then EJBs may be a good choice. So much is made of the transaction

management capability of EJBs that their deployment-descriptor-based security management

features are overlooked. This capability is very powerful; if your application's users

fit into distinct roles and the rules for those roles dictate which users can write what

data, EJBs are a good choice.


2 When Not to Use EJBs
There are several situations in building a software application—even an "enterprise"

software application—in which using EJBs may actually be a barrier to meeting your

business goals. The following list represents places where you might not want to use

EJBs:

 


Read-mostly applications

If your application requires only (or even mostly) database reads (as opposed to writes),

then the added complexity and performance overhead of EJBs may be unwarranted. If your

application is only reading and presenting data, you should go with straight JDBC (see

below) or another persistence mechanism. That said, if your application's writes

(database update and inserts) require transactional support (especially if those

transactions go over multiple systems), then EJBs may be the way to go—at least for the

write portion of the application.

 


Applications requiring thread control

If your application design requires extensive use of threads, then the EJB spec actually

prevents you from using EJBs (although some EJB container vendors may provide nonportable

ways around this restriction). Container systems manage resources, transactions,

security, and other qualities of service using threads; threads you create are outside of

the container's control and can potentially cause system failures. Also, EJB containers

may distribute EJBs across multiple JVMs, preventing the synchronization of threads.

 


Performance

Because EJBs do so much more than plain Java classes, they are slower than plain Java

classes. The EJB container has to do a lot: maintain transactional integrity, manage bean

instances and the bean pools, enforce security roles, manage resources and resource

pools, coordinate distributed operations, synchronize shared services (if the vendor

offers clustering capabilities), and so on. The security and transactional management

operations can have a significant impact on the performance of method calls (on both

local and remote interfaces). If you require real-time or near-real-time performance

characteristics, EJB may not be your best choice.


3 Alternatives to EJB
There are several alternatives to EJB; some of them are growing in popularity and

maturity. EJBs still rank as the de facto standard for enterprise transactional needs,

but some of the alternatives, like JDO, are also available.

3.1 JDBC

3.2 Java Data Objects

3.3 Others

Castor JDO (http://www.exolab.org)

Hibernate (http://www.hibernate.org)

Prevayler (http://www.prevayler.org)


As you can see, there are several alternatives to EJB. If your application doesn't need

the complexity or some of the features of EJB, take a look around. Data persistence with

Java has been around for some time and there is a wide assortment of approaches.
 


  --相关文章--
· 配置WebLogic Server集群二(组图) (2007-04-17)
· 配置WebLogic Server集群一(组图) (2007-04-17)
· 程序员应用EJB 3.0必要的准备 (2007-04-17)
· 用EJB 3.0开发企业级Bean组件初体验 (2007-04-17)
· 漫谈EJB在Java中的应用 (2007-04-17)
· 深入探究EJB应用技术的体系结构 (2007-04-17)

版权所有©2005-2006 JAVA资源网 渝ICP备05007591号 虚拟主机 | 关于我们 | 联系方式 | 广告业务 | 网站地图 | 友情链接