8. As noted earlier, stateless session beans model tasks don’t maintain conversational state. This means that session beans model tasks can be completed in a single method call, such as placing a bid. However, this does not mean that all stateless session beans contain a single method.<o:p></o:p>
9. Three types of business interfaces correspond to the different access types:<o:p></o:p>
Local interface<o:p></o:p>
A local interface is designed for clients of stateless session beans collocated in the same container (JVM) instance.<o:p></o:p>
Remote interface<o:p></o:p>
Clients residing outside the EJB container’s JVM instance must use some kind of remote interface. Remote business interfaces do have one special requirement: all parameters and return types of interface methods must be Serializable. This is because only Serializable objects can be sent across the network using RMI.<o:p></o:p>
<o:p> </o:p>
Web service endpoint interface<o:p></o:p>
The third type of interface is specific to stateless session beans that you haven’t seen yet: the web service endpoint interface (also known as SEI). The ability to expose a stateless session bean as a SOAP-based web service is one of the most powerful features of EJB 3.<o:p></o:p>
10. Stateful session beans are guaranteed to maintain conversational state.<o:p></o:p>
11. Since stateful session beans cannot be pooled and reused like stateless<o:p></o:p>
beans, there is a real danger of accumulating too many of them if we don’t have a way to destroy them. Therefore, we have to define a business method for removing the bean instance by the client using the @Remove annotation.<o:p></o:p>
(由于有状态session bean不能像无状态session bean放入对象池而重复使用,所以如果我们不能及时销毁,就会累积许多的风险。我们必须使用@Remove标注来定义一个业务方法去移去bean实例。)<o:p></o:p>
12.A stateful session bean cannot have a web service endpoint interface.<o:p></o:p>
This is because SOAP-based web services are inherently stateless in nature.(有状态session bean不能实现 web 服务endpoint接口,这是由于基于SOAP的web 服务本质上是无状态的。)<o:p></o:p>
13<o:p></o:p>
<v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype><v:shape id="_x0000_i1025" style="WIDTH: 414.75pt; HEIGHT: 243pt" type="#_x0000_t75"><v:imagedata o:title="" src="file:///C:\DOCUME~1\pengch\LOCALS~1\Temp\msohtml1\01\clip_image001.emz"></v:imagedata></v:shape><o:p></o:p>
<o:p> </o:p>
14. To outline some of the best practices for session beans: <o:p></o:p>
n Choose your bean type carefully. Stateless session beans will be suitable most of the time.(认真选择session的类型,在大多时候无状态session bean是最适合的。)<o:p></o:p>
n Carefully examine interface types for session beans. Remote interfaces involve network access and may slow down your applications.(仔细检查session bean的接口类型。如果是远程接口必须访问网络,这样会减慢系统的访问速度。)<o:p></o:p>
n If you are using DI, make sure you don’t inject a stateful session bean into a stateless session bean or servlet.(如果你使用依赖注入,确保不要将有状态session bean注入到无状态session bean或servlet中。)<o:p></o:p>
n Separate crosscutting concerns such as logging and auditing using business interceptors (which we discuss in chapter 5) instead of spreading them all over the business logic.(使用拦截器代替在整个业务逻辑中传递,来分离像日志和审核等之类的横关切点)<o:p></o:p>
n Closely examine what kind of data you are storing in the conversation state. Try to use small, primitive instance variables in a stateful bean whenever possible as opposed to large nested composite objects.<o:p></o:p>
n Don’t forget to define remove methods in a stateful session bean.<o:p></o:p>
n Tune passivation and timeout configurations to find the optimal values for your application.(调整纯化和超时配置,以录求系统最佳性能。)<o:p></o:p>