Itβs always difficult to find out about the progress of asynchronous processes, especially if you donβt know if they really started.
The best way I've found is to write another function that just gets progress, so if you have a unique identifier for each call, update hashmap using the current process. You can look at Concurrent Hashmap ( http://download-llnw.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentHashMap.html )
Then this other search function will simply accept a unique identifier and return the move back to the client.
If it has not been started, you can also return it, and ideally you would also want to return all error messages that occurred during processing.
Then, when it completes, and you returned an error or success message, then delete it from the hash card, the client received the information, and this information will not change, so you should not store it.
UPDATE:
Create a new function in your interface
String progressDone(String id);
Then you will access this synchronously, since it just goes out and comes back, so it can look for the id in hashmap and return either a percentage of the done or an error message.
But that means that your actual working function needs everyone to put the information in the hash map so often where it is, so I suggested using a parallel hash file, so you donβt have to worry about parallel writing, and thus considerations blocking.
source share