Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When I read <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/doc/EJBConcepts3.html#wp79775" rel="nofollow noreferrer">What is a Session Bean?</a> section of the J2EE 1.4 tutorial:</p> <blockquote> <h2>Stateless Session Beans</h2> <p>A <em>stateless session</em> bean does not maintain a conversational state for a particular client. When a client invokes the method of a stateless bean, the bean's instance variables may contain a state, but only for the duration of the invocation. When the method is finished, the state is no longer retained. Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client.</p> </blockquote> <p>In your case, the call to <code>methodB()</code> from <code>methodA()</code> will be on the same instance and is equivalent to <code>this.methodB()</code>. I'm thus tend to say that <code>methodB()</code> can't output something else that the value that what was passed to <code>methodA()</code>. </p> <p>This is confirmed by the first sentence in section 7.11.8 in the <a href="http://download.oracle.com/otn-pub/jcp/7294-ejb-2.0-fr2-spec-oth-JSpec/ejb-2_0-fr2-spec.pdf" rel="nofollow noreferrer">EJB 2.0 spec</a>: <em>"The container must ensure that only one thread can be executing an instance at any time".</em> This means you cannot come to a situation where data (in your instance variables) from different clients (threads) will be mixed. You are ensured unique access to the instance variables until <code>methodA()</code> has returned!</p> <p>That said, I'm not saying that you don't have a problem somewhere. But I don't think that your pseudo code is equivalent.</p> <p>(EDIT: Having read some comments to the OP's question, there is now clearly a doubt about the pseudo code and semantic used. I'm clarifying possible consequences below.)</p> <p>As underlined by Rocket Surgeon, what do you mean exactly by <em>class variable</em>? Do you really mean <em>class variable</em> as opposed to <em>instance variable</em>? If yes, the pseudo code doesn't reflect it but this will clearly lead to unpredictable behavior. Actually, from section 24.1.2 (and first point) in the EJB 2.0 spec, it is clear that you are not allowed to write data to a class variable (although you can do it). There must be a good reason for this :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload