In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are InstanceContext and ConcurrencyMode in WCF". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is InstanceContext and ConcurrencyMode in WCF".
First, follow the script. The instance of WCF is specified by the InstanceContext attribute. The available values are Single, PerSession, and PerCall. Concurrency is specified by the ConcurrencyMode attribute. Available values are Single, Multiple, and Reentrant. There are three or three or nine combinations of them. The concurrency mode of Reentrant is essentially a special case of Single and will be discussed at last. InstanceContext is used to control the number of service objects, and ConcurrencyMode is used to control whether service objects can serve multiple requests at the same time.
All right, let's start with an example. if our service is to make breakfast, InstanceContext determines how many masters we have to make breakfast, while ConcurrencyMode decides whether each master can only do it one by one or at the same time. Let's start with a case-by-case explanation:
1. InstanceContext = Single & ConcurrencyMode = Single
InstanceContext = Single our breakfast shop is a master.
ConcurrencyMode = Single master can only do one thing at a time
It is not hard to imagine that if there are more people buying breakfast, there will be a long line, and if the person in front of him wants five sets of breakfast, the person behind will have to wait for that person to finish his turn. The requirement of the master's ability is not high, so it is good to do one thing at a time.
2.InstanceContext = Single & ConcurrencyMode = Multiple
InstanceContext = Single our breakfast shop is a master.
ConcurrencyMode = Multiple master does what needs to be done at the same time
This is what the breakfast shop owner wants. He hires the least people to do the most work, but he is very demanding of the breakfast master, and he has to do a lot of things at a time. You can't make a mess as soon as there are too many people. Make one less of Zhang San's baked cakes and one more bowl of Li Si's soy milk.
3.InstanceContext = PerSession & ConcurrencyMode = Single
InstanceContext = PerSession provides each customer with a special master service (customers are recruited when they come, and fired after they leave)
ConcurrencyMode = Single there is only one master working at a time, and each master can only do one thing at a time.
This is impossible in real life, but it is very common in computers, so my example is only to illustrate the key issues, please don't take it too seriously. At this time, the first customer will have a special master to serve, but we have only one kitchen and can only accommodate one master, so other masters can only wait when making breakfast for Zhang San's master. A master can only do one thing at a time. If a customer asks for a lot of things, the master will do the same. So it can still be single-threaded, but there are more than one master. The requirement of the master's ability is not high, so it is good to do one thing at a time.
4.InstanceContext = PerSession & ConcurrencyMode = Multiple
InstanceContext = PerSession provides each customer with a special master service (customers are recruited when they come, and fired after they leave)
ConcurrencyMode = Multiple all masters work at the same time, and each master can do everything he or she needs to do at the same time.
This is also impossible in real life. At this time, each customer will have a special master to serve, and the chefs can work at the same time, and the chef can do all the breakfasts at the same time. The requirement of the master is higher, because it is only dealing with all the breakfasts of a customer at the same time.
5. InstanceContext = PerCall & ConcurrencyMode = Single
InstanceContext = PerCall provides a special service for each customer for every need (the customer will be hired when the request is made, and the master will be fired after the request is done)
ConcurrencyMode = Single there is only one master to work at a time, and each master only has to do one thing.
This is also impossible in real life. Now there are more masters, as in case 3, there can only be one master to work at a certain time, but the difference is that the master only has to do one thing. The requirement of the master's ability is not high, it is good to be able to do one thing well.
6. InstanceContext = PerCall & ConcurrencyMode = Multiple
InstanceContext = PerCall provides a special service for each customer for every need (the customer will be hired when the request is made, and the master will be fired after the request is done)
ConcurrencyMode = Multiple all the masters work at the same time, and each master only has to do one thing.
This is also impossible in real life. At this time, customer satisfaction is theoretically the highest, every requirement of the customer is done by the master, and all the masters are doing things at the same time. Of course, this is the greatest price to pay for the owner of the breakfast shop. The requirement of the master's ability is not high, it is good to be able to do one thing well.
7. InstanceContext = * & ConcurrencyMode = Reentrant
This situation is quite special, if we do not produce breakfast, we buy it from other breakfast shops and then sell it to customers, the legendary donkey rider. At this time, if the customer says what he needs, it will take 5 seconds for us to call another store to ask for it, and it will take 1 minute for the other stores to deliver the goods, and it will take 5 seconds to deliver the goods to the customers. It can be seen that the in-store processing time is 10s, and a lot of time is spent in the transfer time (calling other services). So at this time, a more reasonable treatment is to use the transfer time to deal with the needs of customers behind, in this 1 minute time can handle the needs of 20 customers, and 20 transfer requests have also been sent. Wait until the first customer's goods are delivered and then transferred back to complete the rest of the service, which can save a lot of waiting time for later customers. Whatever the value of InstanceContext is similar to that of ConcurrencyMode = Single, it is optimized for situations where there are external calls.
Thank you for your reading, the above is the content of "what are InstanceContext and ConcurrencyMode in WCF". After the study of this article, I believe you have a deeper understanding of what InstanceContext and ConcurrencyMode in WCF are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.