企业Beans Enterprise Beans

企业Beans Enterprise Beans

企业bean是实现了EJB技术的Java EE组件技术。企业bean运行在EJB容器里,EJB容器是运行在应用服务器里的运行时环境。(see Figure 1-5, page 11).尽管EJB容器对于开发者来说透明的,但其针对企业bean提供了事务,安全等系统级服务。这些底层服务使你能快速构建和部署企业bean,这些企业bean构成了事务型Java EE企业应用的核心。

什么是企业Bean?

企业Bean由Java语言编写,它是封装了应用业务逻辑的服务器端组件。业务逻辑代码满足了应用的意图。在一个库存管理系统中,例如,企业bean可能会在叫做checkInventoryLevel和orderProduct的方法中实现业务逻辑。远程客户可以通过调用这些方法来访问这个应用提供的库存服务。

企业Bean的优点

从很多方面,企业Bean简化了巨大的分布式企业应用的开发.第一,因为EJB容器为企业Bean提供了系统级服务,Bean开发者能集中精力解决业务问题.由容器而不是企业Bean开发者对诸如事务管理和安全验证等系统级服务负责.

第二,因为Bean而不是客户端包含应用的业务逻辑,客户端开发者可以着重于客户端表现.客户端开发者不必编写实现业务逻辑或数据库访问的代码.因此,客户端变得更瘦,这个优点对于运行于小型设备的的客户端来说非常重要.

第三,因为企业bean是可移植组件,应用组装者可以用已经存在的Bean构建一个新的应用.这些用了标准API的应用程序可以运行在任何Java EE应用服务器上.

什么时候用企业Beans

如果你的应用有如下需求,你就要考虑在你的应用中用企业Bean了:

  • 你的应用必须具可伸缩性.为了满足不断增长的用户量,你可能需要在多个机器上发布你的应用.企业beans可以运行于不同的机器上,而对于客户端来说,它实际运行的位置是透明的.
  • 事务必须确保数据完整.企业Beans支持事务,事务机制管理共享对象的并发访问.
  • 应用需要不同类型的客户端.只需几行代码的改动,客户端就能简单地定位企业beans.企业bean的客户端是多样的,瘦的,多个的. 

企业Beans的类型 

Table 20-1 简要介绍两种类型的企业Beans.以下小节讨论每一种企业Bean的细节.

Table 20-1 Enterprise Bean Types

Enterprise Bean Type

Purpose

Session

完成客户端任务;通常可以实现一个web service

Message-Driven

对特定消息类型,扮演监听者.比如JMS API

 

Table 20-1 summarizes the two types of enterprise beans. The following sections discuss each type in more detail.

Table 20-1 Enterprise Bean Types

Enterprise Bean Type

Purpose

Session

Performs a task for a client; optionally may implement a web service

Message-Driven

Acts as a listener for a particular messaging type, such as the Java

Message Service API

 

什么是Session Bean?

Session Bean代理了一个应用服务器里的客户端.为了访问部署在服务器上的应用,客户端调用session bean的方法.session beana为它的客户完成工作,通过在服务器内部执行业务任务,从而使客户端免于过于复杂.

正如它的名字所暗示的,session bean类似内部会话.一个session bean不能共享,它只能有一个客户,同样,一个内部会话也只能有一个用户.就像一个内部会话一样,一个session bean不是持久的(即,它的数据不被存储在数据库中).当客户结束,session bean也终止,并且再也不能关联到客户.

代码例子,请见Chapter 22.

状态管理模式

Session bean有两种类型:有状态和无状态

有状态session beans

一个对象的状态由它的实例的变量值组成.在一个有状态session bean里,实例变量代表了不同的从client-bean会话.因为客户与它自己的bean互相作用,这个状态也被称为会话状态.

在client-bean会话中,状态会被保留.如果客户除去或终止了bean,会话就会结束,状态也会消失.这种易逝的规则不是问题,不过,因为客户和bean结束了,所以没有必要再保留这种状态.

无状态Session Beans 

无状态session bean不保留与客户的会话状态.当客户调用无状态bean的方法时,bean的实例变量可以保留状态,但只是在这次调用过程中保留.当方法结束,状态也就不会再保留了.除非在方法调用过程中,所有的无状态bean都是同样的,允许EJB容器给客户分配一个bean实例.

因为无状态session bean能支持不同类型的客户,所以它们能为有大量客户的应用提供更好的伸缩性.通常,对于支持同样客户量的应用来说,如果用无状态session bean实现,会比用有状态session bean用更少的bean.

在通常的环境中,EJB容器会些一个有状态sesstion bean来进行secondary storage.但无状态session bean从来不会被用来进行secondary storage.因此,无状态session bean能比有状态session bean提供更好的性能,在bean激活中,从secondary storage中获得有状态session bean的状态增大了资源消耗.

一个无状态session bean可以实现为一个web service,但其他类型的企业bean不能.

什么时候用Session Beans

通常,在下面的环境中,你就该使用session bean:

  • 在任何一个时间点,都只有一个客户访问bean实例
  • Bean状态不需要持久,只是存在与一个很短的时间(可能数小时).
  • Bean需要实现为web service.

如果以下任何一个条件成立,则用有状态session bean合适:

  • Bean的状态代表bean和特定客户的相互作用.
  • Bean需要在客户的方法调用间持有信息.
  • Bean处于客户和其他组件的调解者的角色,代表一个的客户简单的视图.
  • 在后台,bean管理着多个企业bean的工作流.例如,在Chapter 38中的AccountControllerBean.

为了提升性能,如果具有以下特点,你可以选择无状态session bean:

  • Bean状态中没有特定客户的数据.
  • 在一个方法调用中,bean完成了对所有客户的一般性任务.例如,你可以用一个无状态session bean发一封在线订单的确认Email. 

什么是消息驱动Bean?

消息驱动bean是允许Java EE应用异步处理消息的企业bean.它通常作为一个JMS消息监听器,它类似事件监听器,不同的是它监听的是消息而不是事件.消息可以由任何Java EE组件—客户,其他的企业bean,或者web组件—或者一个JMS应用或没有应用Java EE技术的系统发出.消息驱动bean可以处理JMS消息或其他类型的消息.

代码例子, Chapter 23.关于消息驱动bean, Using the JMS API in a Java EE Application (page 1086) and Chapter 33.


什么使消息驱动bean和Session bean不同 What Makes Message-Driven Beans Different from Session Beans?

消息驱动bean和session bean主要的显而易见的不同是客户不会通过接口访问消息驱动bean.接口在小节Defining Client Access with Interfaces中有描述.不同与session bean,消息驱动bean只有一个bean类.

在很多方面,消息驱动bean重组了无状态session bean.

  • 消息驱动bean实例不会为特定客户保存数据和会话信息.
  • 消息驱动bean的所有实例是等价的,允许EJB容器分配一条消息到任何消息驱动bean的实例上.容器可以通过实例池缓存这些实例,以便使消息流能被并发处理.
  • 一个消息驱动bean可以处理来自多个客户的消息.

一个消息驱动bean的实例变量可以包含跨多个客户消息处理的数据.例如,一个JMS API连接,一个打开的数据库连接,或者一个企业bean对象的引用.

客户组件不直接定位消息驱动bean和调用其方法.相反,客户通过发消息给消息目的地来访问消息驱动bean,消息驱动bean类是MessageListener.在通过应用服务器资源进行部署时,你可以分配消息驱动bean的目的地.

消息驱动bean具有以下特征:

  • 它们基于一个单独的客户消息执行.
  • 它们被异步调用.
  • 它们相对短生存周期.
  • 它们不直接表示数据库中的共享数据,但它们可以访问并更新这些数据.
  • 它们没有状态.

The most visible difference between message-driven beans and session beans is that clients do not access message-driven beans through interfaces. Interfaces are described in the section Defining Client Access with Interfaces. Unlike a session bean, a message-driven bean has only a bean class.

In several respects, a message-driven bean resembles a stateless session bean.

  • A message-driven bean's instances retain no data or conversational state for a specific client.
  • All instances of a message-driven bean are equivalent, allowing the EJB container to assign a message to any message-driven bean instance. The container can pool these instances to allow streams of messages to be processed concurrently.
  • A single message-driven bean can process messages from multiple clients.

The instance variables of the message-driven bean instance can contain some state across the handling of client messages--for example, a JMS API connection, an open database connection, or an object reference to an enterprise bean object.

Client components do not locate message-driven beans and invoke methods directly on them. Instead, a client accesses a message-driven bean through JMS by sending messages to the message destination for which the message-driven bean class is the MessageListener. You assign a message-driven bean's destination during deployment by using Application Server resources.

Message-driven beans have the following characteristics:

  • They execute upon receipt of a single client message.
  • They are invoked asynchronously.
  • They are relatively short-lived.
  • They do not represent directly shared data in the database, but they can access and update this data.
  • They can be transaction-aware.
  • They are stateless.

当消息到来,容器调用消息驱动bean的onMessage方法处理消息.onMessage方法合理地将其抛到五种JMS消息类型,并用一致的应用业务逻辑处理它.omMessage方法可以调用helper方法,能调用session bean来处理消息中的信息或将其存储在数据库中.

消息能在一个事务上下文中被传递到消息驱动bean,因此在onMessage方法的所有操作都是一个单独的事务的一部分.如果消息处理回滚,消息也会被退回.更多的信息请看Chapter 23.

When a message arrives, the container calls the message-driven bean's onMessage method to process the message. The onMessage method normally casts the message to one of the five JMS message types and handles it in accordance with the application's business logic. The onMessage method can call helper methods, or it can invoke a session bean to process the information in the message or to store it in a database.

A message can be delivered to a message-driven bean within a transaction context, so all operations within the onMessage method are part of a single transaction. If message processing is rolled back, the message will be redelivered. For more information, see Chapter 23.

什么时候用消息驱动beans When to Use Message-Driven Beans

Session beans允许你发送JMS消息,并同步接受它们,但不是异步.为了避免耗尽系统资源,你可能喜欢在服务器端不用阻塞的同步接受.为了异步接受消息,用消息驱动bean.

Session beans allow you to send JMS messages and to receive them synchronously, but not asynchronously. To avoid tying up server resources, you may prefer not to use blocking synchronous receives in a server-side component. To receive messages asynchronously, use a message-driven bean.

用接口定义客户访问Defining Client Access with Interfaces

这一节的内容只应用于session bean,并不用于消息驱动bean.因为它们有不同的变成模型,消息驱动bean没有定义客户访问的接口.

客户可以通过定义于bean业务接口的方法来访问session bean.业务接口定义了bean的客户视图.其他所有的方面,方法实现和部署设置等对客户来讲都是隐藏的.

设计良好的接口简化了Java EE应用的部署和维护.清晰的接口不仅对客户屏蔽了EJB层的复杂性,还使bean变化内部实现时而用户不受影响.例如,如果你将一个无状态session bean改为一个有状态session bean,你无需改变客户代码.但如果你要修改接口中的方法定义,你就同样需要修改客户代码.因此,接口设计很重要,你需要小心隔绝客户和bean中可能的更改.

当你设计Java EE 应用,你要做的第一个决定是客户用什么方式访问bean:remote,local还是web service.

The material in this section applies only to session beans and not to message-driven beans. Because they have a different programming model, message-driven beans do not have interfaces that define client access.

A client can access a session bean only through the methods defined in the bean's business interface. The business interface defines the client's view of a bean. All other aspects of the bean--method implementations and deployment settings--are hidden from the client.

Well-designed interfaces simplify the development and maintenance of Java EE applications. Not only do clean interfaces shield the clients from any complexities in the EJB tier, but they also allow the beans to change internally without affecting the clients. For example, if you change a session bean from a stateless to a stateful session bean, you won't have to alter the client code. But if you were to change the method definitions in the interfaces, then you might have to modify the client code as well. Therefore, it is important that you design the interfaces carefully to isolate your clients from possible changes in the beans.

When you design a Java EE application, one of the first decisions you make is the type of client access allowed by the enterprise beans: remote, local, or web service.

远程客户 Remote Clients

企业bean的远程客户具有如下特征:

  • 与它访问的企业bean运行在不同机器和不同的JVM里. (不必一定运行在不同的JVM里.)
  • 可以是web组件,应用客户或其他企业bean.
  • 对于远程客户,企业bean的位置是透明的.
为了创建一个有远程访问的企业 bean, 你必须把企业的业务接口标记成 @Remote  interface. remote interface 定义了特定bean的业务和生存期方法.例如,  BankAccountBean的远程接口就可能有方法deposit和credit.  Figure 20-1 显示了企业 bean 的客户视图 .   To create an enterprise bean that has remote access, you must annotate the business interface of the enterprise bean as a  @Remote  interface. The remote interface defines the business and lifecycle methods that are specific to the bean. For example, the remote interface of a bean named  BankAccountBean  might have business methods named  deposit  and  credit Figure 20-1 shows how the interface controls the client's view of an enterprise bean.


Figure 20-1 Interfaces for an Enterprise Bean with Remote Access

本地接口 Local Clients

本地客户具有这些特征:

  • 必须与其访问的企业bean运行于同一个JVM.
  • 可以是web组件或另外一个企业bean.
  • 对于本地客户,其访问的企业bean的位置是透明的.

为了构建一个允许本地访问的企业bean,你必须将其业务方法标记为@Local interface.本地接口定义了bean的业务和生存期方法.


决策是远程还是本地访问 Deciding on Remote or Local Access

是否允许远程和本地访问取决于以下因素.

  • 相关的bean的紧或松耦合:紧耦合的bean依赖于其他bean.例如,一个结束的销售订单必须给客户发送一个确认订单结束的email.如果SalesOrder 有状态session bean包含订单应用的业务逻辑, 无状态session beanCustomerContact给客户发送确认email.则这些session bean就可以描述为紧耦合.紧耦合bean是本地访问的好的候选者.因为它们在一起被作为一个逻辑单元,它们经常互相调用并且能从本地调用中获得性能提升的好处. 客户类型:如果一个企业bean被应用客户访问,就该被允许远程访问.在生产环境中,客户几乎总是运行在应用服务器之外的机器上.如果企业bean的客户是web组件或其他企业bean.访问类型取决于你想如何分布你的组件.
  • 组件分布:Java EE应用是可伸缩的,因为服务器端组件可以被分布在多个机器上.在一个分布式系统中,例如,web组件可能运行于多个不同的服务器上.在分布式的场景中,企业bean允许远程访问.
  • 性能:基于诸如网络带宽等因素,远程调用会比本地调用慢一些.但从另一个角度讲,如果你在在不同的服务器上分布你的组件,你将从整体上提升系统性能.这些内容是一般化的;实际的性能会因为不同的操作环境变化.无论如何,你要注意你的应用设计如何影响性能.

如果你不确定bean的访问方式,就选择remote接口.这个选择给你带来了可伸缩性.将来,你可以分布你的组件来满足增长的应用请求.

尽管很罕见,企业bean可以同时允许远程和本地接口访问.这样的bean需要用@Remote 和@Local标记业务方法.


Web Service Clients

Web service客户可以通过两种方式访问Java EE应用.第一,客户可以访问由JAX-WS创建的web service. (更多信息关于 JAX-WS, 看Chapter 15Building Web Services with JAX-WS, page 497.)第二, web service客户可以调用无状态session bean的方法.消息bean可以被web service客户访问.

只要用正确的协议(SOAP, HTTP, WSDL),任何web service都能访问无状态session bean,而不管客户是否由java语言写成.客户也不关心service是用什么技术实现的,如无状态session bean,JAX-WS或者其他技术.另外,企业bean和web组件也可以是web service的客户.这个伸缩性使你可以把Java EE应用和web service集成起来.

一个web service客户通过bean的web service的endpoint实现类来访问无状态session bean.只有被标记为@WebMethod的业务方法才能被web service客户调用.

代码例子, 看 A Web Service Example: HelloServiceBean (page 754).

A web service client can access a Java EE application in two ways. First, the client can access a web service created with JAX-WS. (For more information on JAX-WS, see Chapter 15Building Web Services with JAX-WS, page 497.) Second, a web service client can invoke the business methods of a stateless session bean. Message beans cannot be accessed by web service clients.

Provided that it uses the correct protocols (SOAP, HTTP, WSDL), any web service client can access a stateless session bean, whether or not the client is written in the Java programming language. The client doesn't even "know" what technology implements the service--stateless session bean, JAX-WS, or some other technology. In addition, enterprise beans and web components can be clients of web services. This flexibility enables you to integrate Java EE applications with web services.

A web service client accesses a stateless session bean through the bean's web service endpoint implementation class. Only business methods annotated as a @WebMethod may be invoked by a web service client.

For a code sample, see A Web Service Example: HelloServiceBean (page 754).

方法参数和访问Method Parameters and Access

访问方式影响被客户调用的bean的方法参数.接下来的主题关于方法参数和方法返回值.

The type of access affects the parameters of the bean methods that are called by clients. The following topics apply not only to method parameters but also to method return values.

隔绝 Isolation

远程调用的参数比本地调用更加孤立.远程调用中,客户和bean操作的是不同的参数对象的拷贝.如果客户改变了对象值,bean中相应的对象的值不会改变.这一层隔绝可以帮助保护bean,以防数据被意外更改.

在本地调用中,客户和bean都可以更改同一个参数对象.通常,你不能依赖于本地调用的这个效用,因为很可能你会分布你的组件,用远程调用替代本地调用.

远程客户,web service客户操作实现了web service的bean的参数对象的拷贝.

The parameters of remote calls are more isolated than those of local calls. With remote calls, the client and bean operate on different copies of a parameter object. If the client changes the value of the object, the value of the copy in the bean does not change. This layer of isolation can help protect the bean if the client accidentally modifies the data.

In a local call, both the client and the bean can modify the same parameter object. In general, you should not rely on this side effect of local calls. Perhaps someday you will want to distribute your components, replacing the local calls with remote ones.

As with remote clients, web service clients operate on different copies of parameters than does the bean that implements the web service.

访问数据的粒度 Granularity of Accessed Data

因为远程接口比本地接口慢些,所以远程接口的参数粒度相对要粗些.粗粒度对象比细粒度对象包含了更多的数据,所以调用次数可以少些.同样的原因,web service服务客户的调用的方法参数的粒度也会粗些.

 

企业bean的内容

为了开发一个企业bean,你必须提供以下文件:

  • 企业bean类: 实现定义在远程接口中的业务方法,和任何会调方法
  • 业务接口: 业务接口定义了需要被企业bean实现的业务方法
  • Helper类: 企业bean需要的其他类,比如exception和utility 类.

你要把前面列表里的这些文件打包到EJB JAR文件, EJB JAR是存储企业bean的模块.一个EJB JAR是可移植的,也可以被用于不同的应用.为了组装Java EE应用,你打包一个或多个模块—比如EJB JAR文件到一个EAR文件.EAR是一个持有整个应用的卷文件.当你部署包含了EJB JAR的EAR文件时,你也在应用服务器上部署了企业bean.你也可以部署不包含于EAR文件的EJB JAR文件.

To develop an enterprise bean, you must provide the following files:

  • Enterprise bean class: Implements the methods defined in the business interface and any life cycle callback methods.
  • Business Interfaces: The business interface defines the methods implemented by the enterprise bean class.
  • Helper classes: Other classes needed by the enterprise bean class, such as exception and utility classes.
You package the files in the preceding list into an EJB JAR file, the module that stores the enterprise bean. An EJB JAR file is portable and can be used for different applications. To assemble a Java EE application, you package one or more modules--such as EJB JAR files--into an EAR file, the archive file that holds the application. When you deploy the EAR file that contains the bean's EJB JAR file, you also deploy the enterprise bean to the Application Server. You can also deploy an EJB JAR that is not contained in an EAR file.



Figure 20-2 Structure of an Enterprise Bean JAR

企业bean的命名规则 Naming Conventions for Enterprise Beans

因为企业bean由多个部分组成,在应用中遵循一定的命名规则是必要的. Table 20-2 概述了这份指导中的这个例子的命名规则.

Table 20-2 企业bean命名规则 

Item

Syntax

Example

Enterprise bean name

<name>Bean

AccountBean

Enterprise bean class

<name>Bean

AccountBean

Business interface

<name>

Account

 

Because enterprise beans are composed of multiple parts, it's useful to follow a naming convention for your applications. Table 20-2 summarizes the conventions for the example beans in this tutorial.

Table 20-2 Naming Conventions for Enterprise Beans 

Item

Syntax

Example

Enterprise bean name

<name>Bean

AccountBean

Enterprise bean class

<name>Bean

AccountBean

Business interface

<name>

Account

企业bean生命周期 The Life Cycles of Enterprise Beans

在企业bean的生命期或生命循环中,企业bean经过了不同的阶段.所有的企业bean类型有状态bean,无状态bean或消息驱动bean有不同的生命循环.

下面的章节用代码例子介绍了这些方法.

An enterprise bean goes through various stages during its lifetime, or life cycle. Each type of enterprise bean--stateful session, stateless session, or message-driven--has a different life cycle.

The descriptions that follow refer to methods that are explained along with the code examples in the next two chapters. If you are new to enterprise beans, you should skip this section and run the code examples first.

有状态session bean的生命循环 The Life Cycle of a Stateful Session Bean

Figure 20-3图示了session bean在生命期的阶段.客户通过一个无状态session bean的引用初始化了bean的生命期.容器完成依赖注射和标记为@PostConstruct的方法调用,这样,bean现在就准备好被客户调用其业务方法了.

Figure 20-3 illustrates the stages that a session bean passes through during its lifetime. The client initiates the life cycle by obtaining a reference to a stateful session bean. The container performs any dependency injection and then invokes the method annotated with  @PostConstruct , if any. The bean is now ready to have its business methods invoked by the client. 



Figure 20-3 Life Cycle of a Stateful Session Bean

在ready阶段,EJB容器可以决定钝化还是活化,bean则移置内存或二级存储.(典型地,EJB容器用最近访问优先策略来查询一个活化的bean).EJB容器调用标记为@PrePassivate的方法,在活化它之前.如果客户调用正在活化的bean的业务方法,EJB容器激活这个bean,调用标记为@PostActivate的方法,把它移植ready状态.

在生命期的最后,客户调用标记为@Remove的方法,EJB容器调用标记为@PreDestroy的方法.bean的实例就准备垃圾回收了.

你的代码控制唯一的生命循环方法:标记为@Remove的方法.在Figure 20-3中,所有其他方法都由容器调用.

While in the ready stage, the EJB container may decide to deactivate, or passivate, the bean by moving it from memory to secondary storage. (Typically, the EJB container uses a least-recently-used algorithm to select a bean for passivation.) The EJB container invokes the method annotated @PrePassivate, if any, immediately before passivating it. If a client invokes a business method on the bean while it is in the passive stage, the EJB container activates the bean, calls the method annotated @PostActivate, if any, and then moves it to the ready stage.

At the end of the life cycle, the client invokes a method annotated @Remove, and the EJB container calls the method annotated @PreDestroy. The bean's instance is then ready for garbage collection.

Your code controls the invocation of only one life-cycle method: the method annotated @Remove. All other methods in Figure 20-3 are invoked by the EJB container. See Chapter 35 for more information.

无状态session bean的生命周期 The Life Cycle of a Stateless Session Bean

因为无状态session bean永远不会钝化,它的生命期只有两个阶段:不存在和准备业务方法调用. Figure 20-4图示了无状态session bean的两个阶段.

Because a stateless session bean is never passivated, its life cycle has only two stages: nonexistent and ready for the invocation of business methods. Figure 20-4 illustrates the stages of a stateless session bean.


Figure 20-4 Life Cycle of a Stateless Session Bean

客户通过无状态session bean的引用初始化其生命循环.容器完成所有的依赖注射并调用所有标记为@PostConstruct的方法.bean现在就准备客户调用其业务方法.

在生命循环最后,EJB容器调用标记为@PreDestroy的方法.bean实例就被准备垃圾收集了.

The client initiates the life cycle by obtaining a reference to a stateless session bean. The container performs any dependency injection and then invokes the method annotated @PostConstruct, if any. The bean is now ready to have its business methods invoked by the client.

At the end of the life cycle, the EJB container calls the method annotated @PreDestroy. The bean's instance is then ready for garbage collection.

消息驱动bean的生命循环The Life Cycle of a Message-Driven Bean

Figure 20-5 图示了消息驱动bean的生命循环的两个阶段 the stages in the life cycle of a message-driven bean.

EJB容器总是创建一个消息驱动bean的实例池.对每个实例,EJB容器完成如下任务:

  1. 如果消息驱动bean用依赖注射,容器就在初始化这些实例前注射入引用.
  2. 容器调用所有标记为@PostConstruct的方法.

Figure 20-5 illustrates the stages in the life cycle of a message-driven bean.

The EJB container usually creates a pool of message-driven bean instances. For each instance, the EJB container performs these tasks:

  1. If the message-driven bean uses dependency injection, the container injects these references before instantiating the instance
The container calls the method annotated  @PostConstruct , if any.



Figure 20-5 Life Cycle of a Message-Driven Bean

就像无状态session bean,消息驱动bean永远不会钝化,它也只有两个阶段:不存在和准备接受消息.

在生命循环的最后,容器调用所有标记为@PreDestroy的方法.bean实例就可以被垃圾收集了.

Like a stateless session bean, a message-driven bean is never passivated, and it has only two states: nonexistent and ready to receive messages.

At the end of the life cycle, the container calls the method annotated @PreDestroy, if any. The bean's instance is then ready for garbage collection.

更多信息Further Information

关于更多企业bean技术,请看下面:

  • Enterprise JavaBeans 3.0 规范:

http://java.sun.com/products/ejb/docs.html

  • 企业Bean网站:

http://java.sun.com/products/ejb

For further information on Enterprise JavaBeans technology, see the following:

  • Enterprise JavaBeans 3.0 specification:

http://java.sun.com/products/ejb/docs.html

  • The Enterprise JavaBeans web site:
http://java.sun.com/products/ejb
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值