进行带有超时的 EJB 调用

发布于 2024-12-27 10:55:29 字数 342 浏览 3 评论 0原文

我有一个调用 EJB B 的 EJB A。 UI 等待响应的时间不应超过 30 秒。如果某些数据丢失,它应该返回部分响应。

如何在 EJB B 上定义超时(30 秒的时间限制)?

我可以将 EJB B 定义为返回 FutureAsynchronous,然后执行 Future.get(30, TimeUnit.SECONDS). 但这是最好的解决方案吗?

谢谢

PS 我用 glassfish 3.1

I have an EJB A that invokes EJB B. The UI should not wait for more than 30 seconds for a response. If some data is missing, it should return a partial response.

How can I define a timeout (time limit of 30 seconds) on EJB B?

I can define EJB B as Asynchronous that returns Future, and then do Future.get(30, TimeUnit.SECONDS).
But is it the best solution?

thank you

P.S. I use glassfish 3.1

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

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

发布评论

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

评论(3

π浅易 2025-01-03 10:55:29

我建议为此使用事务超时。

我认为没有标准的配置方法,因此它取决于应用程序服务器。我假设您想针对每个类或方法专门设置它。

对于WebLogic,您可以在“transaction-descriptor”中的“weblogic-ejb-jar.xml”中指定它,或者使用注释“@TransactionTimeoutSeconds”。

http://docs.oracle.com/cd/E12839_01/web.1111/e13719/ejb_jar_ref.htm#i1506703

http://docs.oracle.com/cd/E21764_01/web .1111/e13720/annotations.htm#i1438354

对于JBoss AS 您可以使用注释“@TransactionTimeout”或在“jboss.xml”中设置事务超时。

https://community.jboss.org/wiki/TransactionTimeout

我确信有类似的配置选项在每个应用程序服务器中。

I would suggest using the transaction timeout for this.

I don't think there is a standard way of configuring it so it would depend on the application server. I assume you want to set it specifically per class or method.

For WebLogic you can specify it in "weblogic-ejb-jar.xml" in the "transaction-descriptor" or use the annotation "@TransactionTimeoutSeconds".

http://docs.oracle.com/cd/E12839_01/web.1111/e13719/ejb_jar_ref.htm#i1506703

http://docs.oracle.com/cd/E21764_01/web.1111/e13720/annotations.htm#i1438354

For JBoss AS you could set the transaction timeout using the annotation "@TransactionTimeout" or in "jboss.xml".

https://community.jboss.org/wiki/TransactionTimeout

I am sure there are similar configuration options in every application server.

长发绾君心 2025-01-03 10:55:29

无法中断目标 EJB。唯一真正的选择是目标 EJB 协作并定期检查它是否超出了预期的目标响应时间。

即使您使用@Asynchronous并且Future.get超时,您也只是解除了客户端等待结果的阻塞;目标EJB将继续执行并消耗资源。但是,使用异步方法,您确实可以使用 Future.cancelSessionContext.wasCancelCalled 进行一些内置协作取消。

There is no way to interrupt a target EJB. The only real option is for the target EJB to cooperatively and periodically check whether it has exceeded the intended target response time.

Even if you use @Asynchronous and the Future.get times out, you've simply unblocked the client from waiting for the result; the target EJB will continue to execute and consume resources. However, with asynchronous methods, you do have the benefit of some builtin cooperative cancellation using Future.cancel and SessionContext.wasCancelCalled.

你丑哭了我 2025-01-03 10:55:29

要为 bean 配置适用于其所有方法的超时,您必须在 glassfish-ejb-jar.xml 中配置属性 cmt-timeout-in-seconds

该超时值由启动新事务的 bean 的所有方法使用,当它们加入其他正在进行的事务时不适用。

还可以参考此链接了解有关超时的更多详细信息。

To configure timeout for a bean which applies to all its methods, you have to configure the attribute cmt-timeout-in-seconds in glassfish-ejb-jar.xml.

This timeout value is used by all the methods of the bean that initiates a new transaction, not applicable when they join other ongoing transaction.

Also can refer this link for further details on timeout.

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