来自不同客户端的EJB3状态并发调用 [英] EJB3 stateful concurrent calls from different clients

查看:166
本文介绍了来自不同客户端的EJB3状态并发调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个丰富的客户端swing应用程序调用远程有状态的ejb。我使用JBoss 6.0。

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

我已经在两个不同的机器,即不同的ip地址,jvms等部署了客户端。

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

stateful具有以下代码:

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;
    }
}

客户端有以下代码:

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

然后,当我运行第一个客户端时,ejb执行println命令并开始执行循环(如预期)。但是,当我在不同的机器上运行第二个客户端时,ejb不打印任何东西,直到第一个方法调用完成。换句话说,有状态bean似乎还不能处理来自不同客户端的并发调用。

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.

如果我们看看println命令,我们可以看到:

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.

推荐答案

这是一个影响JBoss AS 6的错误: https://issues.jboss.org/browse/JBAS- 9416

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

这篇关于来自不同客户端的EJB3状态并发调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆