I have a web service that is based on Java classes. Is it possible to run code after an acknowledge message has been returned within Java method of the called operation.
To understand better, this is the workflow:
- Call a specific operation (method) of my web service
- Start processing
- Sent an ack that the processing has been started (this is done be a return value)
- Continue processing
Threads do not work, since the threads need to be terminated before the return of the method.
Does anybody has an idea how to implement this scenario or an alternative to it?
Thanks in advance.
You will need to use Threads for this, as you are splitting program flow into two; the returning path and the processing path are separating and running alongside each other.
If you need the acknowledgement for the method start to be sent by the return of the method then why can’t your service providing methods look as simple as something like this?
The service will be started, then the method will return (thus notifying that the process has started) whilst the processing continues until the thread ends…
Am I missing something here about what you need to achieve?
Hope this helps.
EDIT:
It seems that some answers have been engineered to address problems which I did not see as being presented as part of the question. Here are some assumptions I made when making my answer, presented so that anyone reading this answer might have a better idea of when it might not apply to their particular situation:
This is for a situation where you want only to acknowledge that a service has conceptually speaking begun execution. The acknowledgement can give no information about the success of any part of this execution or its initialisation, only that it has conceptually started, that is to say that the Associated Runnables run() will be called at some point.
Of course if you want the execution to start and the caller to return, then the significance of the acknowledgement will necessarily be limited by just exactly how much of the task waited to be executed before returning, here no waiting is done and the acknowledgement is returned immediately, and so no extra information can be given.