会话bean的会话状态 [英] conversational state of session beans

查看:111
本文介绍了会话bean的会话状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读一本关于Java EE 6的书,我遇到了以下部分:

I'm reading a book on Java EE 6 and I met with the following parts:

无状态:会话bean之间不包含会话状态方法,任何
实例都可以用于任何客户端。

有状态:会话bean包含会话状态,必须在单个用户的方法中保留

会话状态是什么意思?有没有真实世界的例子来解释它?

What does "conversational state" mean ? Has somebody real world example to explain it ?

提前致谢。

II。为什么豆类的这种分类如此重要?无论是正确的解释还是初学者(乍看之下)都没有说什么。
所以,多亏了你,我得到了逻辑上的区别,但为什么这种行为如此重要呢?

II. Why this classification of beans so important ? It tells nothing with correct explanation either or for beginner (at first sight ) So thanks to you I got the logical difference, but why this kind behaviour so important ?

推荐答案

在最基本的会话状态是指实例字段的值。

at the most basic, "conversational state" refers to the value of instance fields.

对于无状态会话bean,容器不保证后续方法调用将使用相同的EJB实例(来自池),因此您不能假设您放置的值当你调用bean方法时,当你再次调用该方法(或bean的另一个方法)时,它仍然存在。

For stateless session beans, the container does not guarantee that subsequent method invocations will use the same EJB instance (from the pool), hence you cannot assume that the values you placed when you call a bean method, will still be there when you call the method again (or another method of the bean).

对于有状态会话bean,容器保证后续调用将使用相同的EJB实例,因此您可以保留实例字段值。

For stateful session beans, the container guarantees that subsequent calls will use the same EJB instance, hence you can keep instance field values.

为了举例,假设您有一个具有增量()的bean和retrieve()方法。增量会增加存储值,并且retrieve会获取当前存储的值。

For the sake of an example, say you have a bean that has an increment() and a retrieve() method. Increment increases the stored value, and retrieve gets the current stored value.

对于无状态会话bean,如果调用increment()方法5次,则无法保证当你执行retrieve()时,你会得到一个5.它由容器决定它将分配给你的调用。因此,如果为您分配了一个新的EJB实例,那么您将获得零。容器也可能没有清理你的EJB实例,因此有可能获得5 - 但不能保证。

For a stateless session bean, if you call the increment() method 5 times, it is not guaranteed that when you do a retrieve(), you'll get a 5. It is up to the container which EJB it'll assign to your call. So if you are assigned a new EJB instance, then you'll get a zero. It is also possible that the container has not cleaned up your EJB instance, so it might be possible to get a 5 -- but it is not guaranteed.

对于有状态会话bean,如果你调用增量方法5次,当你检索到值时,你会得到一个5.容器保证你第一次调用时使用的EJB将用于所有后续调用。

For a stateful session bean, if you call the increment method 5 times, when you retrieve the value you'll get a 5. The container guarantees that the EJB that was used the first time you called will be used for all subsequent calls.

这篇关于会话bean的会话状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆