有什么方法可以了解EJB异步过程的进度吗? [英] Is there any way to know the progress of a EJB Asynchronous process?

查看:112
本文介绍了有什么方法可以了解EJB异步过程的进度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从EJB异步过程中获取进度百分比。

I'm trying to get the percentage of the progress from a EJB Asynchronous process. Is this possible?

有人知道我该怎么做吗?

Does anyone have an idea how I could do this?

推荐答案

了解异步过程的进度总是很棘手,尤其是如果您不知道它们是否真正开始的话。

To get to know the progress of asynchronous processes is always tricky, especially if you don't know if they have actually started yet.

我发现的最好方法是编写另一个仅能获取进度的函数,因此,如果每个调用都有一些唯一的ID,请使用当前进程更新 hashmap 。您可能需要查看Concurrent Hashmap( http://download-llnw.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentHashMap.html

The best way I have found is to write another function that just gets the progress, so, if you have some unique id for each call, then update a hashmap with the current process. You may want to look at Concurrent Hashmap (http://download-llnw.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentHashMap.html)

然后,另一个查找功能将只获取唯一的ID,然后将进度返回给客户端。

Then this other lookup function will just take the unique id, and return the progress back to the client.

如果尚未启动,则还可以返回它,理想情况下,您可以希望也能够返回处理中出现的任何错误消息。

If it hasn't been started, you can also return that, and ideally you may want to also be able to return any error messages that came up in the processing.

然后,当它完成时,您返回了错误消息或成功,然后从哈希图中将其删除。 ,则客户获得了该信息,并且该信息不会更改,因此也没有必要保留它。

Then, when it has finished, and you returned the error message or success, then delete it from the hashmap, the client got the information, and that info won't change, so no point it keeping it around.

更新:

在您的界面中创建一个新函数

In your interface make a new function

String progressDone(String id);

然后您将同步引用它,因为它刚好会出来并马上回来,因此可以查找< hashmap 中的code> id 并返回完成百分比或错误消息。

You will then refer to that synchronously, as it just goes out and comes right back, so it can look up the id in the hashmap and return either the percentage done or an error message.

但是,这意味着您的实际辅助函数需要经常将信息放置在哈希图中,以了解其位置,这就是为什么我建议使用并发哈希图的原因,这样您就不必担心并发写入,并且因此锁定注意事项。

But, this means that your actually worker function needs to every so often put information in the hashmap as to where it is, which is why I suggested using the concurrent hashmap, so that you don't have to worry about concurrent writes, and so locking considerations.

这篇关于有什么方法可以了解EJB异步过程的进度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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