3

I have a rich client swing application calling a remote stateful ejb. I'm using JBoss 6.0.

I have deployed the client in two different machines, i.e, different ip address, jvms, etc.

The stateful has the following code:

@Stateful
public class MyStateful implements MyStatefulRemote{

public void test(){     
    System.out.println(this);
    System.out.println(Thread.currentThread());
    System.out.println(Thread.currentThread().getThreadGroup());

    // cpu intensive task                
    String value = "";
    for (int j = 0; j < Integer.MAX_VALUE; j++) {
        value = "" + j;
    }
}

And the client has the following code:

...
String JNDI_FACADE = "MyStateful/remote";
InitialContext context = new InitialContext();
MyStatefulRemote my = (MyStatefulRemote) context.lookup(JNDI_FACADE);
my.test();

Then, when I run the first client, the ejb executes the println commands and begins to execute the loop (as expected). However, when I run the second client in a different machine, the ejb does not print anything until the first method invocation has finished. In other words, it seems that the stateful bean has not been able to handle concurrent calls , even from different clients.

If we look at the println commands, we can see:

br.com.alta.MyStateful@61ef35
WorkerThread#6[192.168.7.58:54271]
java.lang.ThreadGroup[name=jboss,maxpri=10]

and when the server finishes the execution of the first invocation, then, the second invokation prints the output:

br.com.alta.MyStateful@17539b3
WorkerThread#1[192.168.7.53:54303]
java.lang.ThreadGroup[name=jboss,maxpri=10]

I can notice that there are two different instances of the stateful (as expected, one instance for each client), and they run in different threads.

When I use stateless instead of stateful, it works. However, in my application i need to keep some data from the client, and the stateful seems more suitable.

Marcio Aguiar
  • 14,231
  • 6
  • 39
  • 42
r0drigopaes
  • 103
  • 1
  • 8

2 Answers2

5

It seems that this is a bug affecting JBoss AS 6: https://issues.jboss.org/browse/JBAS-9416

Marcio Aguiar
  • 14,231
  • 6
  • 39
  • 42
0

By default, EJB does not allow for concurrent calls to stateful beans. I know, that on Weblogic server you can enable such feature using allow-concurrent-calls property. On JBoss, most probably you will have to redesign your architecture and use stateless beans.

omnomnom
  • 8,911
  • 4
  • 41
  • 50
  • The problem is that it should not allow concurrent calls on the SAME SFSB INSTANCE and the log show clearly two separate instances. – Marcio Aguiar Aug 10 '11 at 17:38
  • 3
    Piotrek, i had understood that this restriction applies only when make concurrent calls to the same bean instance. Also, the server creates a different instance of the stateful for each different client. Then, as we are making concurrent calls to different stateful bean instances, I would expect to have the server handling both requests simultaneously. – r0drigopaes Aug 10 '11 at 17:46
  • 2
    From the specification: ... 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 OF A STATEFUL BEAN CLASS, if the second client is a client of the bean’s business interface, the concurrent invocation may result in the second client receiving the javax.ejb.ConcurrentAccessException – r0drigopaes Aug 10 '11 at 17:51
  • sorry, I did not get that your question is about different instances- my fault. – omnomnom Aug 11 '11 at 06:45