I wrote an application which is sending Sip Invite Message to a destination. After some period (10 ms,100 ms,whatever) response message comes from destination. I'm doing some businnes in processResponse.
So this issues are asynchronous!!! By the way i'm using nist library for sip messaging.
Another project team requesting a library from me. They want to use my application by calling synchronously.
What is the simplest way to do this ?
How can i call my asynchronous task via synchronous method ?
alp carsikarsi wrote:Thanks jayesh. is this solution works on heavy simultaneus request load ?
Any solution that uses a synchronous call that waits on a background job to complete will have an inherent cost:- The thread that called your synchronous method will wait till the background process is complete. This means that if your app server spawns a thread for each request, there is one more thread for the OS to keep track off, or if the app serves uses a thread pool (as most app servers do), there is one less thread to service other requests. Either way, you will be bottlenecking. This may or may not be a big deal depending on the frequency of requests, and time taken to process each request.
Besides that, if you use the mechanism that I described, there will be an overhead while you continuously poll for completion. It depends on what the cost of each call is. I am not familiar with the library that you are using. If the mechanism that Stephen described is available, it should be less costly, since you will be spending more time in wait
Joined: Dec 27, 2005
In the attachment i sent the flow.
Stephan van Hulst
Joined: Sep 20, 2010
After you send the request, how would you then retrieve the response? Do you need to provide a "callback" to the library?
If so, then you should write an await() signal() notification system between the initial thread and the callback thread.
Note that I wrote this code from the top of my head and I did not compile or test it. Use it only to give you an idea of how to solve the problem.