views:

73

answers:

2

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

or maybe any ideas ????

Thanks in advice

+2  A: 

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

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)

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.

UPDATE:

In your interface make a new function

String progressDone(String 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.

James Black
thx for the answer, but i still don't get how to get the process and do the id call thing, how do you do this ?? is some function or i've to do it for myself ??
ErVeY
You will need to do it yourself.
James Black
thx for the answer, but i store the progress in the session object already, maybe could not be the best solution but it works perfectly i'll try that too, always welcome new knowledge ;D
ErVeY
A: 

In EJB3.1 @Asynchronous method-calls can return java.util.concurrent.Future, this interface provides information boolean isCancelled() or boolean isDone(), but no information if the execution started. From my point of view, there is no way to get the information if the process started its execution via the EJB-Container in standard ways.

Michael Konietzka
yes i know about the java.util.concurrent.future and i tryied to set a property of the bean with the porcentage and access by the getter method, but i get a 0% response til the task ends and then i got 100%maybe if i store it in the session object i could access, any sugest ??
ErVeY