Before talking about the watchdog principle, let’s take a look at the following two lines of code. Which line uses the watchdog?
Second line of code
With the source code, we will find that if the expiration time is brought, the lua script will be executed, the lock operation will be executed, and the expiration time will be the 10s you set, so it is generally based on the average time of business execution
Increase the expiration time appropriately to ensure that the lock has not expired before the business is executed.
The first line of code
If you follow the code carefully
Regarding the watchdog part: there will be an expiration time when it is locked, and then the watchdog is actually a timed task, which is executed once every 1/3 of the default time, which is 10s.
Then the expiration time is full, so the lock will not automatically expire before the execution of the business is completed, and the lock will automatically expire after the business is completed. There is an expiration time that naturally solves the deadlock
If you want to learn more, please refer to this article
https://blog.csdn.net/weixin_33054847/article/details/112285924
Then in actual application, the expiration time is usually set manually