Concurrent access to session EJBs disallowed ?

I'm developing a web based application that uses multiple frames in a

browser window. Three of those frames go to a stateful session EJB to get

the data to be displayed in them (it's different data that's all held in a

common session).

What I'm finding is that I often get an exception thrown when trying to

invoke a method on the session EJB from one or more of the JSPs:

weblogic.ejb.extensions.LockTimedOutException: Lock for primaryKey:996674553807_2

could not be acquired without waiting.

This doesn't seem to be a Weblogic-specific problem: I've looked around in

various discussion groups, and have found that this is apparently correct

behavior. According to the EJB 1.1 (and 2.0) spec, it is documented behavior

that the EJB container should throw a java.rmi.RemoteException if a client

tries to invoke more than one method at the same time in an instance of a

session EJB (the LockTimedOutException above extends RemoteException).

An excerpt from the EJB 1.1 spec (section 6.5.6, "Serializing session bean methods"):

"Clients are not allowed to make concurrent calls to a session object. If a

client-invoked business method is in progress on an instance when another

client-invoked call, from the same or different client, arrives at the same

instance, the container must throw the java.rmi.RemoteException to the

second client."

The question I have is: how can this be ? My intuition would be that the

EJB container should manage access to EJBs similarly to how thread

synchronization works: it should block additional accesses until the first

access finishes.

I can't be the only developer in the world that has multiple JSPs in a

framed window all banging on a session EJB at the same time. What have

other people done to work around this problem ? Session EJBs are supposed

to maintain conversational state; does this really mean that I can't access

this state from more than one window at a time in my client application ?

My current solution is to wrap invocations to the session EJB in a "while"

loop and retry a certain number of times until the operation succeeds. This

works pretty well, but it makes the code nasty and doesn't really resolve

the basic problem: it's clearly a race condition, and with enough bad timing

some operations will always exceed their max retries and fail.

Is there any prospect that this will change in future revisions of the EJB

spec ? This seems much too restrictive for enterprise applications written

on an inherently multithreaded platform like Java.

[2756 byte] By [bgw2] at [2007-9-26 2:41:39]
# 1

Hi,

Remind me what the different context,s mean!

There is application, sesion,page - any others?

Does not a session mean what it says, adding the word client - meaning a client session, and does a page session mean that it exists as part of a page, and does not an application context mean that it lasts as long as that application?

Correct me please, maybe i am missing something(or the memory needs replacing!!).

bset kev

kwilding at 2007-6-29 10:17:37 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

I assume you are using the Stateful Session Bean as a singleton cache to service your client.

The first thing to note is that your "client" in this case is a JSP or servlet. If you have 3 frames on your web page, the browser will send 3 requests to the web server, which would likely mean that 3 threads will be used on the web server to service your request concurrently. Therefore, as far as your Stateful Session Bean is concerned, it has 3 different clients, hence the exception.

Depending on the type of information and the rate at which it is updated, you could cache the information within the web tier. Create a JavaBean (or a simple Java class) to contain the information, and then store it in the user HttpSession object (for example). Your JSPs or servlets would go there for the information instead of to the session bean. This would also give improved performance since you eliminate the network call to the session bean. Check out the Pet Store demo that's part of the Blue Prints on the Java website for more info.

Note that there are plenty of other designs that may be suitable. This is just one idea.

Cheers,

Aaron.

hstech at 2007-6-29 10:17:37 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Hi Bruce,

We have encountered similar problems in our project. But we got around it because we are using WebLogic for our Application server. Weblogic supports concurrent calls to Stateful Session beans. Though the specification clearly says that concurrent access in prohibited, apparently bea has got around this problem.

By specifying a parameter (think it is called allow-concurrent-access) in the weblogic-ejb.xml it is possible to have concurrent client access to the same stateful session bean.This makes the solution native to weblogic.The client calls are automatically serialized by the container. We have tested this.

Hope that helps,

Joshi

shripadvj at 2007-6-29 10:17:37 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
I have made <allow-concurrent-calls>true..........But still i'm getting the same exception.Can anybody help me in this regard?Thanks in advance~amit
amitsehgal_us at 2007-6-29 10:17:37 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...