I have devoloped a WebService (WS1) in Java which is deployed in a Tomcat Server.
If certain conditions are met, WS1 needs to invoke another WebService (WS2) to run in parallel. Is this possible? or does the WS1 has to wait for the response of WS2 to keep running. The point of this is not delaying the response of WS1 as it is not dependant of WS2. However, WS2 trigger IS dependant of WS1 and that’s how my problem starts.
My hipothetical solution to this issue is to create a separate servlet which invokes WS2 without delaying WS1. How can I implement it or can anyone think of a better solution?
It depends what you want to achieve. If you just want to kickoff the second WS, you could create a new local thread and do the call. The second WS might even support asynchronous calls so that you are not blocked after calling it. Creating a new thread would work as follows.
First, you need a class for this thread. This class would take care of communicating with WS2:
In your WS1 request handler, you just need to kick-off this thread, e.g.:
That’s it, but of course there are many ways in Java to create another thread. That’s up to you to investigate the best possible solution.