English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I was told that stateful session bean holds state of the variables between client calls. In this context what does client call refer to. Is it the period for which the client browser is open . If i create muliple instance of EJB in my client code will the state of the variable be retained for all the instance or will it vary for each instance?

2006-11-20 23:14:01 · 2 answers · asked by venkat 1 in Computers & Internet Programming & Design

2 answers

stateful beans are full of state. Stateless ones have less of it :-)
"client call" is a single remote method invocation.
Stateful beans are more similar to "normal" local class instances. If you call a function on it, that sets a value for some instance variable, and then call another function, it'll see the value that the previous function set. If the bean is stateless, then calling the first function will generally have no effect on what the second one sees.
The states between different instances is, of course, different. Just like it is the case with regular java class instances.

stateful beans is generally a bad programming practice. It wasn't even a term until recently, when a gush of bad programmers came in, and started "engineering" around it - "stateless" was a term, because it denotes a good engineering concept, and "stateful" is, pretty much, just a lack of such.
When your server is stateless, you can be sure, that the result you get from calling a function depends only on the parameters you pass in. With a stateful "design", there is no such guarantee, you have to know the entire history of the server session to know what to expect from a function call.

2006-11-21 01:01:04 · answer #1 · answered by n0body 4 · 1 0

I think this article will help you out:

http://safari.oreilly.com/0789725673/ch09lev1sec2

In short, with a stateless session bean, you are not guarenteed to be using the same session instance (you may but don't count on it) even if you use the same interface.

With the stateful session bean, you will have access to the same instance so long as you hold on to the interface. Just be sure to remove() the interface when you are done so you can free up resources.

2006-11-21 00:34:09 · answer #2 · answered by mchenryeddie 5 · 0 1

fedest.com, questions and answers