Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / June 2004

Tip: Looking for answers? Try searching our database.

[EJB] Why this behaviour. Confusing. EJB gurus please explain

Thread view: 
Venky Venkatramani - 17 Jun 2004 22:55 GMT
Code snippetss

Jsp A

OrderBean myABean = getOrderBeanInstace(); // Do not look for syntax
please
myABean.ExecuteOrder("Pen");

Jsp B

OrderBean myBBean = getOrderBeanInstance();
myBBena.ExecuteOrder("Car");

class Bean
{
  public String OrderItem;
  public ExecuteOrder(String x)
  {
     OrderItem = x;  // I am saving this as I have to share it with
other methods but is being simplfied here
     sleep(3 mins)
     SendORder(OrderItem); // as OrderItem may be changed in the
methods I intend to call in-lieu of sleep 3 mins
  }
}

Now as you can see SendOrder is not guaranteed to send Pen for the
first Jsp and Car for th second Jsp. (EJB 2.1 FR specs Section 7.8)

I do not understand why. I looked in the net. When JSP 2 requires an
instance why the container (EJB) is not saving the context fully
(including OrderItem) of JSP A. If I push the OrderItem in the method
it will save the context and this will work. I am not lookign for
work-arounds but the reason for this specification.

JSP A or JSP B is not assured of sending the correct orderitem. It is
blamed upon the bean developer. The object's context (instead of
method's cotnext) if I am saying this right needs to be restored by
the container. Why this is not being specified ?

For an analogy if there are wine glasses available in the counter
(consdier them as beans). I come in fill it in with wine and take a
sip. I am swapped out. Then next person comes in and requests a glass.
He is given the same 'dirty' glass. Even that is okay with me. The
problem is when he is pre-empted I am getting a corrupted object.

This is all happening in a stateless environment with in a call. I am
not leaving VOLUNTARILY (so that it becomes a requirement for
statefulness between calls) but being pre-empted out by the
OS/JVM/Container (in a stateless environment). So my call is in
IN-FLIGHT.

Can someone explain the decision to leave the specs this way? I
believe Java Gurus have a reason to do this.

Thanks

Venky
John C. Bollinger - 18 Jun 2004 14:48 GMT
> Code snippetss
>
[quoted text clipped - 24 lines]
> Now as you can see SendOrder is not guaranteed to send Pen for the
> first Jsp and Car for th second Jsp. (EJB 2.1 FR specs Section 7.8)

No, I don't see that.  If the OrderItem string were cached as an
instance variable then your statement would be correct, but for a local
variable it is not correct.  Do note that caching the String in an
instance variable makes the bean stateful, but it is incumbent upon the
bean packager to declare it so in its deployment descriptor.

> I do not understand why. I looked in the net. When JSP 2 requires an
> instance why the container (EJB) is not saving the context fully
> (including OrderItem) of JSP A. If I push the OrderItem in the method
> it will save the context and this will work. I am not lookign for
> work-arounds but the reason for this specification.

You seem to have some misunderstandings.  There is no context pushing
and popping involved in EJB.  Stateless session beans are
context-independent -- that's what "stateless" means for them.  Stateful
session beans are associated with one client at a time, and are only
assigned to a new client after any previous client releases them or
times out; managing conversational state is the responsibility of the
bean developer.  Entity beans may be used simultaneously or serially by
multiple clients, in which case the results are governed by the exact
timing and sequence of events and the level of transaction isolation.

> JSP A or JSP B is not assured of sending the correct orderitem. It is

By which you mean that in your application it doesn't always happen?

> blamed upon the bean developer. The object's context (instead of
> method's cotnext) if I am saying this right needs to be restored by
> the container. Why this is not being specified ?

It very likely _is_ a problem with the bean implementation class or
deployment descriptor.  The only thing I can suggest from what you have
presented is that the bean may be declared stateless in its deployment
descriptor but nevertheless exhibit stateful behavior.  The solution in
that case would be either to make the bean truly stateless (often not
very difficult) or to declare it stateful.

> This is all happening in a stateless environment with in a call. I am

Define "stateless environment".  What do you mean by that, and how are
you certain it is so?

> not leaving VOLUNTARILY (so that it becomes a requirement for
> statefulness between calls) but being pre-empted out by the
> OS/JVM/Container (in a stateless environment). So my call is in
> IN-FLIGHT.

Statefulness is not just about what happens between calls.  If there is
any way for concurrent method invocations on the same bean instance to
interfere with each other then the bean is by definition stateful.

Please do also understand that it is possible for client code to
manipulate a bean instance in ways forbidden by EJB.  One example would
be allowing multiple client threads to use a stateful session bean
instance concurrently.  If the client violates the spec then the
behavior of the EJB is not defined.

John Bollinger
jobollin@indiana.edu


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.