I have learned about mutex and semaphore but don't know if it's applicable here for web service, as calls are done separatetly.
Yes, you could. Application servers need to be multithreaded to handle simultaneous client requests. WCF, ASP.NET, and Web Services applications are implicitly multithreaded.
Mutex stands for mutual exclusion. The Mutex type ensures blocks of code are executed only once at a time.
Semaphore can be useful in limiting concurrency — preventing too many threads from executing a particular piece of code at once.
Do you understand why it fails and are you sure the root cause can't be fixed directly? Adding some more code to prevent a problem to happen rather than fixing its root cause sounds something that should be really avoided as much as you can.
The problem is due to an external API that we do not control and that fails (cannot create java VM) we we try to access it we two calls too quickly.
after some test I noticed that a Global Variable was used by all calls (tested using two separate instance), so I think that I will start with that option and will check more deeply semaphore in case it's not enough
Member
2 Points
91 Posts
How to manage single external resource access from web service
Nov 15, 2016 09:05 AM|Denfer06|LINK
I have a web service that expose a feature that access an external resource.
The issue is that if you try to access the resource from two service call too closer the second call failed.
I have learned about mutex and semaphore but don't know if it's applicable here for web service, as calls are done separatetly.
any help will be welcomed
All-Star
17652 Points
3510 Posts
Re: How to manage single external resource access from web service
Nov 16, 2016 06:44 AM|Chris Zhao|LINK
Hi Denfer,
Yes, you could. Application servers need to be multithreaded to handle simultaneous client requests. WCF, ASP.NET, and Web Services applications are implicitly multithreaded.
Mutex stands for mutual exclusion. The Mutex type ensures blocks of code are executed only once at a time.
Semaphore can be useful in limiting concurrency — preventing too many threads from executing a particular piece of code at once.
reference:
https://msdn.microsoft.com/en-us/library/system.threading.semaphore(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.threading.mutex(v=vs.110).aspx
Best Regards,
Chris
All-Star
48520 Points
18073 Posts
Re: How to manage single external resource access from web service
Nov 16, 2016 07:16 AM|PatriceSc|LINK
Hi,
Do you understand why it fails and are you sure the root cause can't be fixed directly? Adding some more code to prevent a problem to happen rather than fixing its root cause sounds something that should be really avoided as much as you can.
Member
2 Points
91 Posts
Re: How to manage single external resource access from web service
Nov 16, 2016 08:19 AM|Denfer06|LINK
The problem is due to an external API that we do not control and that fails (cannot create java VM) we we try to access it we two calls too quickly.
after some test I noticed that a Global Variable was used by all calls (tested using two separate instance), so I think that I will start with that option and will check more deeply semaphore in case it's not enough