开发者

EJB3 stateful concurrent calls from different clients

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

I hav开发者_如何学运维e 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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜