I have some findings about technical aspects of EJB, Can someone help me to adjust the problems?
1. No concurrent access to Stateful Session Beans
The EJB spec doesn't allow for concurrent access to a Stateful Session Bean(SFSB). The spec disallows creation of threads from within an EJB, and also explicitly requires the container to throw an exception if multiple callers
invoke it concurrently. This requirment really limits the practical usage of Stateful Session beans. For example, a SFSB it won't be able to handle the very common scenario of multiple requests coming in concurrently from a single browser (a single web page may imply many concurrent requests); you cannot use the state in the SFSB to conditionally redirect image requests.
To solve this, you may enforce request serialization in the servlet; but this becomes virtually impossible if the servlets handling incoming request are executing on different machines.
2. No support for Threads in JSP, Servlet, or EJB
Also, a little known fact regarding thread support in JSP and Servlet (these are specified, along with EJB, in the mother-of-all enterprise Java standards, the J2EE). Quote from the Servlet 2.2 spec:
A Servlet Container may place security restrictions on the environment that a servlet executes in. In a Java 2 Platform Standard Edition 1.2 (J2SE) or Java 2 Platform Enterprise Edition 1.2 (J2EE)environment, these restrictions
should be placed using the permission architecture defined by Java 2 Platform. For example, high end application servers may limit certain action, such as the creation of a Thread object, (emphasis mine) to insure that other components of the container are not negatively impacted.
One developer reported that the J2EE ref implementation from Sun does not permit thread creation in JSP or Servlets. The code will generates thread exceptions. With BEA WebLogic it works, but is supposedly "unsupported."
With IBM WebSphere, it works.
EJB v2.0 does not add thread support.
3. No Failover of Session Beans
Excerpt from BEA's online WebLogic documentation,
>, regarding Stateful EJBs (SFSB's):
When a home creates a stateful bean, it returns a stub that is pinned to the server hosting the home. Because this bean holds state on behalf of the client, all calls must be routed to the single instance. So in the case of a
stateful bean, load-balancing and fail-over only occur during calls to the home. Once the stateful bean has been created, all calls for it must go to the same server. (emphasis mine) If a failure occurs, the client code must
catch the remote exception and retry by creating a new instance using the clustered home.
There is no support in the EJB specification for persistence or failover of stateful session beans. Nor is there any support for HTTP Session persistence in the JSP or Servlet specifications. Any persistence or failover is a "value-add" which his provided differently by each vendor. BEA does not yet provide it. IBM provides it, but it implies a proprietary API, and quality and scalability are suspect.