EJB3 stateful concurrent calls from different clients

流过昼夜 提交于 2019-12-12 19:15:47

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/7001740/ejb3-stateful-concurrent-calls-from-different-clients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!