来自不同客户端的 EJB3 有状态并发调用

发布于 2024-11-28 18:05:11 字数 1350 浏览 3 评论 0原文

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

我已经将客户端部署在两台不同的机器上,即不同的ip地址、jvm等。

有状态的有以下代码:

@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 似乎无法处理并发调用,即使是来自不同客户端的调用。

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

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

当服务器完成第一个调用的执行时,第二个调用将打印输出:

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

我可以注意到有两个不同的有状态实例(如预期的那样,一个是每个客户端的实例),并且它们在不同的线程中运行。

当我使用无状态而不是有状态时,它可以工作。但是,在我的应用程序中,我需要保留来自客户端的一些数据,有状态似乎更合适。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昇り龍 2024-12-05 18:05:11

这似乎是影响 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

刘备忘录 2024-12-05 18:05:11

默认情况下,EJB 不允许并发调用有状态 bean。我知道,在 Weblogic 服务器上,您可以使用 allow-concurrent-calls 属性启用此类功能。在 JBoss 上,您很可能必须重新设计架构并使用无状态 bean。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文