Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the choice and choice of multiline programming

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

How to understand the choice and choice of multi-line programming? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

The actual project use case is more real, so I now talk about my usual business carding in the project to deal with, for reference, write bad do not spray, there is a better solution, welcome to communicate. Thank you!

Taking and giving up in multithreading

Or use the data about hotel rooms in the previous articles as an example, assuming that the system connects the interface data of x-Cheng, y-long and Q at the same time, and the user enters a hotel reservation page, the system needs to go to a third party in real time to get the real-time dynamic data of the corresponding room of the hotel and present it to the user, but in this process, the user can not wait too long. And can provide as many channels as possible for users to choose, so how to achieve this requirement at this time?

Students who have worked on the aggregation platform, whether it is hotels, air tickets, consulting, etc., will more or less encounter such similar business scenarios. Let's share below how we usually achieve it.

To put it simply, it is a logic of taking or leaving. You think, ah, the query efficiency of different interfaces is different, and the processing time of the same interface is also different at different times. In some special cases, it is possible that an interface data needs to wait 5-10s or even longer to take out the data. At this time, it is impossible for users to wait so long. If this is the case, it is estimated that users will be scared away. And waiting like this will also bring a lot of pressure to the system, especially during the peak period of activity, which is directly a bottleneck of the system.

In order to achieve this goal, then in the implementation, the first thing we should think of is the interface that does not return data within the agreed time, then we just give up and show only the data that has been fetched to the user.

So how to achieve it technically?

In terms of implementation, with Task, everything becomes so easy, because the Task.Wait method has taken such a scenario into account for us and can be used directly.

As you can see, in the overloaded method, there is a timeOut field that is used to discard unfinished thread tasks that have timed out. How exactly should I use it?

Through the above running results, we found that only Ctrip returned the data within 1 second, then only the data of Ctrip was returned to the user. This example has been realized in this way. Of course, I believe you may have a better realization. Welcome to communicate and learn together. Thank you.

This is the answer to the question about how to understand the choice and choice of multi-line programming. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report