A countdown method, device, electronic device and storage medium
By generating key-value pairs of countdown objects and tasks, and using thread pools to manage countdown tasks, the inaccuracy problem caused by countdown timers in the prior art is solved, and a more accurate countdown function is achieved.
Patent Information
- Application Number
- CN202110956945.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-19
- Publication Date
- 2025-06-20
- Estimated Expiration
- 2041-08-19
AI Technical Summary
The countdown timer in the prior art relies on system time, resulting in inaccurate timing, especially when system time changes.
By generating key-value pairs of countdown objects and countdown times, countdown objects and countdown tasks, the call thread pool obtains countdown tasks within the set time period, and performs countdown tasks based on two types of key-value pairs to update the countdown time and display it, avoiding repeated calls to system time during the countdown period.
It solves the problem of inaccurate timing caused by the countdown timer due to system time changes, and realizes a more accurate countdown function.
Smart Images

Figure CN113886031B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular, to a countdown method, device, electronic device, and storage medium. Background Art
[0002] The countdown timer is applied to the Android system and is used to provide an accurate countdown function on the graphical interface. The existing countdown timers are the CountDownTimer provided by Android natively and the timers Timer&TimerTask provided by Java. Among them, CountDownTimer uses the method of sending Messages regularly by Handler, which depends on the system time. According to the test results, there will be an error of 0.5 to 1 second every 60 seconds, and the error size varies depending on different mobile phones. When Timer executes periodic tasks, it also depends on the system time. If the current system time changes, it will affect the execution of Timer, resulting in problems such as inaccurate timing. Summary of the Invention
[0003] The present invention provides a countdown method, device, electronic device, and storage medium to solve the problem that the countdown timer in the prior art depends on the system time.
[0004] The present invention provides a countdown method, including:
[0005] Obtain a countdown object and a countdown time, generate a first key-value pair based on the countdown object and the countdown time, and display the countdown time;
[0006] Create a corresponding countdown task according to the countdown object, and generate a second key-value pair based on the countdown object and the countdown task;
[0007] Call a thread pool to obtain the countdown task within a set time period, and execute the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it.
[0008] According to the countdown method provided by the present invention, the generating of the first key-value pair based on the countdown object and the countdown time includes:
[0009] Use the countdown object as the key of the first key-value pair, and use the countdown time as the value of the first key-value pair;
[0010] The generating of the second key-value pair based on the countdown object and the countdown task includes:
[0011] Use the countdown object as the key of the second key-value pair, and use the countdown task as the value of the second key-value pair.
[0012] According to a countdown method provided by the present invention, after generating the first key-value pair based on the countdown object and the countdown time, the method further includes:
[0013] Determine whether a first cache for storing the first key-value pair exists;
[0014] If a first cache for storing the first key-value pair exists, write the first key-value pair into the first cache;
[0015] If a first cache for storing the first key-value pair does not exist, create the first cache and write the first key-value pair into the first cache.
[0016] According to a countdown method provided by the present invention, after generating the second key-value pair based on the countdown object and the countdown task, the method further includes:
[0017] Determine whether a second cache for storing the second key-value pair exists;
[0018] If a second cache for storing the second key-value pair exists, write the second key-value pair into the second cache;
[0019] If a second cache for storing the second key-value pair does not exist, create the second cache and write the second key-value pair into the second cache.
[0020] According to a countdown method provided by the present invention, when the calling thread pool obtains the countdown task within a set time period and executes the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it, the method includes:
[0021] The calling thread pool obtains the countdown task from the second cache within a set time period;
[0022] Based on the first key-value pair and the second key-value pair, execute the countdown task to perform countdown processing on the current countdown time to obtain the updated countdown time;
[0023] Determine whether the updated countdown time in the first key-value pair reaches a set time threshold;
[0024] If the set time threshold is reached, terminate the call to the thread pool to obtain the countdown task, remove the first key-value pair and the second key-value pair from the first cache and the second cache respectively, and display the end of the countdown through the countdown object;
[0025] If the set time threshold is not reached, display the updated countdown time through the countdown object, and continue to execute the step of performing countdown processing on the updated countdown time for the countdown task.
[0026] According to a countdown method provided by the present invention, based on the first key-value pair and the second key-value pair, performing the countdown task to perform countdown processing on the current countdown time to obtain an updated countdown time, including:
[0027] Determining a countdown object corresponding to the countdown task based on the second key-value pair;
[0028] Obtaining a corresponding first key-value pair from the first cache based on the countdown object;
[0029] Determining a countdown time corresponding to the countdown object based on the first key-value pair;
[0030] Obtaining the current countdown time in the first key-value pair, performing countdown processing on the current countdown time by executing the countdown task, and writing the countdown time after the countdown processing as the updated countdown time into the first key-value pair.
[0031] According to a countdown method provided by the present invention, after obtaining the corresponding first key-value pair from the first cache based on the countdown object, it further includes:
[0032] If the first key-value pair does not exist in the first cache, terminating the call to the thread pool to obtain the countdown task, and removing the second key-value pair from the second cache.
[0033] The present invention further provides a countdown device, including:
[0034] A countdown acquisition module, configured to acquire a countdown object and a countdown time, generate a first key-value pair based on the countdown object and the countdown time, and display the countdown time;
[0035] A countdown task creation module, configured to create a corresponding countdown task according to the countdown object, and generate a second key-value pair based on the countdown object and the countdown task;
[0036] A countdown execution module, configured to call a thread pool to obtain the countdown task within a set time period, execute the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it.
[0037] According to a countdown device provided by the present invention, the countdown acquisition module is further configured to:
[0038] Use the countdown object as the key of the first key-value pair and the countdown time as the value of the first key-value pair;
[0039] The described countdown task creation module is further configured to:
[0040] Use the countdown object as the key of the second key-value pair, and use the countdown task as the value of the second key-value pair.
[0041] According to a countdown device provided by the present invention, the countdown acquisition module is further configured to:
[0042] Determine whether a first cache for storing the first key-value pair exists;
[0043] If a first cache for storing the first key-value pair exists, write the first key-value pair into the first cache;
[0044] If a first cache for storing the first key-value pair does not exist, create the first cache and write the first key-value pair into the first cache.
[0045] According to a countdown device provided by the present invention, the countdown task creation module is further configured to:
[0046] Determine whether a second cache for storing the second key-value pair exists;
[0047] If a second cache for storing the second key-value pair exists, write the second key-value pair into the second cache;
[0048] If a second cache for storing the second key-value pair does not exist, create the second cache and write the second key-value pair into the second cache.
[0049] According to a countdown device provided by the present invention, the countdown execution module is further configured to:
[0050] Call a thread pool to obtain a countdown task from the second cache within a set time period;
[0051] Based on the first key-value pair and the second key-value pair, execute the countdown task to perform countdown processing on the current countdown time to obtain an updated countdown time;
[0052] Determine whether the updated countdown time in the first key-value pair reaches a set time threshold;
[0053] If the set time threshold is reached, terminate the call to the thread pool to obtain the countdown task, remove the first key-value pair and the second key-value pair from the first cache and the second cache respectively, and display the end of the countdown through the countdown object;
[0054] If the set time threshold is not reached, display the updated countdown time through the countdown object, and continue to execute the step of performing countdown processing on the updated countdown time for the countdown task.
[0055] A countdown device provided by the present invention, the execution countdown module is further configured to:
[0056] Determine the countdown object corresponding to the countdown task based on the second key-value pair;
[0057] Obtain the corresponding first key-value pair from the first cache based on the countdown object;
[0058] Determine the countdown time corresponding to the countdown object based on the first key-value pair;
[0059] Obtain the current countdown time in the first key-value pair, execute the countdown task to perform countdown processing on the current countdown time, and write the countdown time after countdown processing as the updated countdown time into the first key-value pair.
[0060] A countdown device provided by the present invention, the execution countdown module is further configured to:
[0061] If the first key-value pair does not exist in the first cache, terminate the call to obtain the countdown task from the thread pool, and remove the second key-value pair from the second cache.
[0062] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the countdown method described in any one of the above are implemented.
[0063] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the countdown method described in any one of the above are implemented.
[0064] The present invention also provides a computer program product, including a computer program / instructions. When the computer program / instructions are executed by a processor, the steps of the countdown method described in any one of the above are implemented.
[0065] A countdown method, device, electronic device, and storage medium provided by the present invention generate key-value pairs of a countdown object and a countdown time, and a countdown object and a countdown task, call a thread pool to obtain a countdown task within a set time period, and execute the countdown task according to the two types of key-value pairs to update the countdown time and display it. It is not necessary to repeatedly call the system time during the countdown, solving the problem that the timer is affected by the change of the system time, resulting in inaccurate timing. Description of the Drawings
[0066] To more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0067] Figure 1 is one of the schematic flowcharts of the countdown method provided by the present invention;
[0068] Figure 2 is the second schematic flowchart of the countdown method provided by the present invention;
[0069] Figure 3 is the third schematic flowchart of the countdown method provided by the present invention;
[0070] Figure 4 is the schematic structural diagram of the countdown device provided by the present invention;
[0071] Figure 5 is the schematic structural diagram of the electronic device provided by the present invention. Detailed Embodiments
[0072] To make the objectives, technical solutions, and advantages of the present invention clearer, the following will clearly and completely describe the technical solutions in the present invention in conjunction with the drawings in the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art without creative efforts based on the embodiments in the present invention belong to the scope of protection of the present invention.
[0073] The following will, in conjunction with the drawings, elaborate on the technical solutions provided by each embodiment of the present invention.
[0074] First, the noun terms mentioned in the embodiments of the present invention will be explained.
[0075] Countdown object: An entity that associates the graphical interface with the countdown logic. When the countdown time changes or the countdown ends normally, the user is notified through the countdown object.
[0076] Countdown time: A time number in seconds.
[0077] Countdown task: A logical entity within the system that establishes the countdown time and maintains key-value pairs for each countdown object.
[0078] Thread pool: used to manage multiple threads. A large number of idle threads are created when the system starts. When a task is received from the program, an idle thread is started to execute this task. After the task is executed, the thread does not die but returns to the thread pool and is set to the idle state, continuing to wait for the next task to be executed.
[0079] Figure 1 It is a schematic flowchart of the countdown method provided by the present invention, as Figure 1 shown, the method includes:
[0080] Step 110, obtain a countdown object and a countdown time, generate a first key-value pair based on the countdown object and the countdown time, and display the countdown time.
[0081] Specifically, obtain a countdown object and a countdown time. Among them, the countdown object is an entity that associates the graphical interface with the countdown logic. When the countdown time changes or the countdown ends normally, the user is notified through the countdown object. The present invention can use the countdown object to immediately notify the user of the current countdown time at the start of the countdown. For example, when the user sets a countdown of 120 seconds, the prior art can only notify "119" after one second, while the present invention can immediately notify the user of the number "120", meeting the user's need to immediately obtain the current countdown time.
[0082] Step 120, create a corresponding countdown task according to the countdown object, and generate a second key-value pair based on the countdown object and the countdown task.
[0083] It should be noted that generating two types of key-value pairs, namely countdown object - countdown time and countdown object - countdown task, not only ensures the uniqueness of the countdown task but also greatly increases the throughput of the entire system and can be applicable to scenarios of multi-task parallelism.
[0084] Step 130, call the thread pool to obtain the countdown task within a set time period, and execute the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it.
[0085] Among them, the thread pool is used to manage multiple threads to obtain and execute countdown tasks. Since the system continuously starts and shuts down threads during multi-threaded operation, the system resources are over-consumed and may cause the collapse of system resources. Using a thread pool can avoid such problems, conveniently manage threads, reduce resource consumption, and thus improve system performance. The existing timer Timer only creates one thread when executing a timed task. If there are multiple tasks and the task time is too long and exceeds the interval time between two tasks, unpredictable problems such as timing confusion will occur. The present invention uses a thread pool to execute countdown tasks, overcomes the defects of Timer, and achieves the effect of isolating tasks from each other and releasing the resources occupied by the mobile phone system when idle.
[0086] The countdown method provided by the present invention generates key-value pairs of a countdown object and a countdown time, and a countdown object and a countdown task, calls a thread pool to obtain a countdown task within a set time period, and executes the countdown task according to the two types of key-value pairs to update the countdown time and display it. There is no need to repeatedly call the system time during the countdown, which solves the problem that the timer is affected by the change of the system time and causes inaccurate timing.
[0087] Further, generating the first key-value pair based on the countdown object and the countdown time includes: using the countdown object as the key of the first key-value pair and the countdown time as the value of the first key-value pair; generating the second key-value pair based on the countdown object and the countdown task includes: using the countdown object as the key of the second key-value pair and the countdown task as the value of the second key-value pair.
[0088] Based on the above embodiments, the present invention uses ConcurrentHashMap to cache and store the first key-value pair and the second key-value pair. Among them, ConcurrentHashMap is a thread-safe and highly concurrent version of HashMap. It is a concurrent container composed of an array and a linked list, and can support 16 threads to execute concurrent write operations and any number of threads to execute read operations. When the thread pool executes the countdown task, it needs to access the first cache and the second cache based on ConcurrentHashMap multiple times to update the countdown time. ConcurrentHashMap can ensure the efficient concurrent execution of multiple tasks.
[0089] Specifically, after generating the first key-value pair based on the countdown object and the countdown time, it is also necessary to determine whether the first cache exists; if the first cache for storing the first key-value pair exists, write the first key-value pair into the first cache; if the first cache for storing the first key-value pair does not exist, create the first cache and write the first key-value pair into the first cache. Similarly, for the second key-value pair, it is also necessary to determine whether the second cache exists; if the second cache for storing the second key-value pair exists, write the second key-value pair into the second cache; if the second cache for storing the second key-value pair does not exist, create the second cache and write the second key-value pair into the second cache.
[0090] The present invention stores two types of key-value pairs in concurrent caches respectively, which can support multiple threads in the thread pool to concurrently access the first key-value pair and the second key-value pair, execute the countdown task to update the countdown time, so as to efficiently perform countdown processing.
[0091] Based on the above embodiments, as Figure 2 shown, step 130 further includes:
[0092] Step 210, calling the thread pool to obtain the countdown task from the second cache within a set time period.
[0093] Specifically, for example, if the set time period is one second, the thread pool performs an operation once every second to obtain the countdown task from the second cache.
[0094] Step 220, based on the first key-value pair and the second key-value pair, execute the countdown task to perform countdown processing on the current countdown time to obtain the updated countdown time.
[0095] Specifically, change the current countdown time according to the set time period. For example, if the set time period is one second, change the current countdown time from i to i - 1.
[0096] Step 230, determine whether the updated countdown time in the first key-value pair reaches the set time threshold. If it reaches the set time threshold, execute step 240; if it does not reach the set time threshold, execute step 250.
[0097] Among them, the value of the set time threshold is 0.
[0098] Step 240, terminate the call to the thread pool to obtain the countdown task, remove the first key-value pair and the second key-value pair from the first cache and the second cache respectively, and display the end of the countdown through the countdown object.
[0099] Specifically, if the countdown time is reduced to 0, it indicates that the current countdown has ended. It is necessary to notify the thread pool to stop obtaining countdown tasks, remove the corresponding first key-value pair and second key-value pair from the first cache and the second cache based on ConcurrentHashMap, and notify the user that the countdown has ended through the countdown object.
[0100] Step 250: Display the updated countdown time through the countdown object, and continue to execute the step of performing countdown processing on the updated countdown time for the countdown task.
[0101] Specifically, if the countdown time is not reduced to 0, display the updated countdown time i - 1 through the countdown object, and continue to repeat the above countdown processing steps for the countdown time i - 1.
[0102] The following is an example to illustrate the above countdown process. For example, the countdown time starts from 10 seconds, the set time period is 1 second, and the time threshold is 0. Execute the countdown task to change the current countdown time to 9 and display it through the countdown object, continue to update the countdown time to 8 until the countdown time is updated to 0, then terminate the current countdown task and notify the user that the countdown has ended.
[0103] The present invention encapsulates a series of operations for calling the thread pool to execute the countdown task, eliminating the need for the caller to repeatedly write code logic such as time counting, achieving the purpose of streamlining the code.
[0104] Based on the above embodiments, as Figure 3 shown, step 210 specifically includes:
[0105] Step 310: Determine the countdown object corresponding to the countdown task based on the second key-value pair.
[0106] Step 320: Obtain the corresponding first key-value pair from the first cache based on the countdown object.
[0107] Step 330: Determine the countdown time corresponding to the countdown object based on the first key-value pair.
[0108] Specifically, the thread pool obtains the countdown task from the second buffer, associates the first key-value pair in the first cache with the current second key-value pair based on the countdown object, and thus obtains the countdown time corresponding to the current countdown task.
[0109] Step 340: Obtain the current countdown time in the first key-value pair, execute the countdown task to perform countdown processing on the current countdown time, and write the countdown time after countdown processing as the updated countdown time into the first key-value pair.
[0110] Specifically, change the current countdown time according to the set time period. For example, if the set time period is one second, change the current countdown time from i to i - 1.
[0111] Based on the above embodiments, after obtaining the corresponding first key-value pair from the first cache based on the countdown object, if the first key-value pair does not exist in the first cache, terminate the call to the thread pool to obtain the countdown task, and remove the second key-value pair from the second cache.
[0112] In summary, the countdown method provided by the present invention generates key-value pairs of a countdown object and a countdown time, and a countdown object and a countdown task, calls a thread pool to obtain a countdown task within a set time period, and executes the countdown task according to the two types of key-value pairs to update the countdown time and display it. It is not necessary to repeatedly call the system time during the countdown, solving the problem that the timer is affected by the change of the system time, resulting in inaccurate timing.
[0113] At the same time, storing the two types of key-value pairs in a concurrent cache respectively can support multiple threads in the thread pool to concurrently access the first key-value pair and the second key-value pair, execute the countdown task to update the countdown time, and thus perform countdown processing efficiently.
[0114] In addition, a series of encapsulations are performed on the operation of calling the thread pool to execute the countdown task, eliminating the need for the caller to repeatedly write code logic such as time counting, achieving the purpose of streamlining the code.
[0115] Next, the countdown device provided by the present invention will be described. The countdown device described below can be correspondingly referred to the countdown method described above.
[0116] Figure 4 For the structural schematic diagram of the countdown device provided by the present invention, as Figure 4 shown, the device includes:
[0117] A countdown acquisition module 410, configured to acquire a countdown object and a countdown time, generate a first key-value pair based on the countdown object and the countdown time, and display the countdown time.
[0118] A countdown task creation module 420, configured to create a corresponding countdown task according to the countdown object, and generate a second key-value pair based on the countdown object and the countdown task.
[0119] A countdown execution module 430, configured to call a thread pool to acquire the countdown task within a set time period, execute the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it.
[0120] The countdown device provided by the present invention generates key-value pairs of a countdown object and a countdown time, and a countdown object and a countdown task, calls a thread pool to obtain a countdown task within a set time period, and executes the countdown task according to the two types of key-value pairs to update the countdown time and display it. It does not need to repeatedly call the system time during the countdown, solving the problem that the timer is affected by the change of the system time, resulting in inaccurate timing.
[0121] Based on the above embodiment, the obtaining countdown module 410 is further configured to:
[0122] Use the countdown object as the key of the first key-value pair, and use the countdown time as the value of the first key-value pair;
[0123] The creating countdown task module is further configured to:
[0124] Use the countdown object as the key of the second key-value pair, and use the countdown task as the value of the second key-value pair.
[0125] Based on the above embodiment, the obtaining countdown module 410 is further configured to:
[0126] Judge whether a first cache for storing the first key-value pair exists;
[0127] If there is a first cache for storing the first key-value pair, write the first key-value pair into the first cache;
[0128] If there is no first cache for storing the first key-value pair, create the first cache and write the first key-value pair into the first cache.
[0129] Based on the above embodiment, the creating countdown task module 420 is further configured to:
[0130] Judge whether a second cache for storing the second key-value pair exists;
[0131] If there is a second cache for storing the second key-value pair, write the second key-value pair into the second cache;
[0132] If there is no second cache for storing the second key-value pair, create the second cache and write the second key-value pair into the second cache.
[0133] The present invention stores the two types of key-value pairs in a concurrent cache respectively, which can support multiple threads in the thread pool to concurrently access the first key-value pair and the second key-value pair, execute the countdown task to update the countdown time, and thus perform countdown processing efficiently.
[0134] Based on the above embodiment, the executing countdown module 430 is further configured to:
[0135] Invoke the thread pool to obtain the countdown task from the second cache within a set time period;
[0136] Based on the first key-value pair and the second key-value pair, execute the countdown task to perform countdown processing on the current countdown time to obtain the updated countdown time;
[0137] Determine whether the updated countdown time in the first key-value pair reaches the set time threshold;
[0138] If the set time threshold is reached, terminate the invocation of the thread pool to obtain the countdown task, remove the first key-value pair and the second key-value pair from the first cache and the second cache respectively, and display the end of the countdown through the countdown object;
[0139] If the set time threshold is not reached, display the updated countdown time through the countdown object, and continue to execute the step of performing countdown processing on the updated countdown time for the countdown task.
[0140] The present invention encapsulates a series of operations for invoking the thread pool to execute the countdown task, eliminating the need for the caller to repeatedly write code logic such as time counting, achieving the purpose of streamlining the code.
[0141] Based on the above embodiments, the countdown execution module 430 is further configured to:
[0142] Determine the countdown object corresponding to the countdown task based on the second key-value pair;
[0143] Obtain the corresponding first key-value pair from the first cache based on the countdown object;
[0144] Determine the countdown time corresponding to the countdown object based on the first key-value pair;
[0145] Obtain the current countdown time in the first key-value pair, execute the countdown task to perform countdown processing on the current countdown time, and write the countdown time after countdown processing as the updated countdown time into the first key-value pair.
[0146] According to a countdown device provided by the present invention, the countdown execution module 430 is further configured to:
[0147] If the first key-value pair does not exist in the first cache, terminate the invocation of the thread pool to obtain the countdown task, and remove the second key-value pair from the second cache.
[0148] In summary, the countdown device provided by the present invention generates key-value pairs of a countdown object and a countdown time, and a countdown object and a countdown task, calls a thread pool to obtain the countdown task within a set time period, and executes the countdown task according to the two types of key-value pairs to update the countdown time and display it. It is not necessary to repeatedly call the system time during the countdown, solving the problem that the timer is affected by the change of the system time, resulting in inaccurate timing.
[0149] At the same time, the two types of key-value pairs are respectively stored in a concurrent cache, which can support multiple threads in the thread pool to concurrently access the first key-value pair and the second key-value pair, execute the countdown task to update the countdown time, and thus perform countdown processing efficiently.
[0150] In addition, a series of encapsulations are performed on the operation of calling the thread pool to execute the countdown task, eliminating the need for the caller to repeatedly write code logic such as time counting, achieving the purpose of streamlining the code.
[0151] Figure 5 An example of the physical structure diagram of an electronic device is shown as Figure 5 shown. The electronic device may include: a processor 510, a communication interface 520, a memory 530, and a communication bus 540. Among them, the processor 510, the communication interface 520, and the memory 530 communicate with each other through the communication bus 540. The processor 510 can call the logical instructions in the memory 530 to execute the countdown method, which includes: obtaining a countdown object and a countdown time, generating a first key-value pair based on the countdown object and the countdown time, and displaying the countdown time; creating a corresponding countdown task according to the countdown object, and generating a second key-value pair based on the countdown object and the countdown task; calling a thread pool to obtain the countdown task within a set time period, and executing the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it.
[0152] In addition, when the logical instructions in the above-mentioned memory 830 are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program codes.
[0153] On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the countdown method provided by the above-mentioned various methods. The method includes: obtaining a countdown object and a countdown time, generating a first key-value pair based on the countdown object and the countdown time, and displaying the countdown time; creating a corresponding countdown task according to the countdown object, and generating a second key-value pair based on the countdown object and the countdown task; calling a thread pool to obtain the countdown task within a set time period, and executing the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it.
[0154] On another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is configured to execute the countdown method provided by the above-mentioned various methods. The method includes: obtaining a countdown object and a countdown time, generating a first key-value pair based on the countdown object and the countdown time, and displaying the countdown time; creating a corresponding countdown task according to the countdown object, and generating a second key-value pair based on the countdown object and the countdown task; calling a thread pool to obtain the countdown task within a set time period, and executing the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it.
[0155] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative effort.
[0156] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0157] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features. And these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A countdown method, characterized in that, Including: Obtain a countdown object and a countdown time, generate a first key-value pair based on the countdown object and the countdown time, and display the countdown time; Create a corresponding countdown task according to the countdown object, and generate a second key-value pair based on the countdown object and the countdown task; Call a thread pool to obtain the countdown task within a set time period, and execute the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it; Among them, the countdown object is an entity that associates the graphical interface with the countdown logic, and the countdown task is a logical entity within the system that establishes the countdown time and maintains the key-value pair for each countdown object.
2. The countdown method according to claim 1, characterized in that, The generating the first key-value pair based on the countdown object and the countdown time includes: Using the countdown object as the key of the first key-value pair and the countdown time as the value of the first key-value pair; The generating the second key-value pair based on the countdown object and the countdown task includes: Using the countdown object as the key of the second key-value pair and the countdown task as the value of the second key-value pair.
3. The countdown method according to claim 2, characterized in that, After generating the first key-value pair based on the countdown object and the countdown time, it further includes: Judge whether a first cache for storing the first key-value pair exists; If there is a first cache for storing the first key-value pair, write the first key-value pair into the first cache; If there is no first cache for storing the first key-value pair, establish the first cache and write the first key-value pair into the first cache.
4. The countdown method according to claim 3, characterized in that, After generating the second key-value pair based on the countdown object and the countdown task, it further includes: Judge whether a second cache for storing the second key-value pair exists; If there is a second cache for storing the second key-value pair, write the second key-value pair into the second cache; If there is no second cache for storing the second key-value pair, establish the second cache and write the second key-value pair into the second cache.
5. The countdown method according to claim 4, characterized in that, The calling the thread pool to obtain the countdown task within a set time period, executing the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it includes: Call the thread pool to obtain the countdown task from the second cache within a set time period; Based on the first key-value pair and the second key-value pair, execute the countdown task to perform countdown processing on the current countdown time to obtain the updated countdown time; Judge whether the updated countdown time in the first key-value pair reaches a set time threshold; If it reaches the set time threshold, terminate the call to the thread pool to obtain the countdown task, remove the first key-value pair and the second key-value pair from the first cache and the second cache respectively, and display the end of the countdown through the countdown object; If it does not reach the set time threshold, display the updated countdown time through the countdown object, and continue to execute the step of performing countdown processing on the updated countdown time for the countdown task.
6. The countdown method according to claim 5, characterized in that, Performing the countdown task based on the first key-value pair and the second key-value pair to perform countdown processing on the current countdown time to obtain an updated countdown time, including: Determining a countdown object corresponding to the countdown task based on the second key-value pair; Obtaining a corresponding first key-value pair from the first cache based on the countdown object; Determining a countdown time corresponding to the countdown object based on the first key-value pair; Obtaining the current countdown time in the first key-value pair, performing the countdown task to perform countdown processing on the current countdown time, and writing the countdown time after countdown processing as the updated countdown time into the first key-value pair.
7. The countdown method according to claim 6, characterized in that, After obtaining the corresponding first key-value pair from the first cache based on the countdown object, further including: If the first key-value pair does not exist in the first cache, terminating the call to the thread pool to obtain the countdown task, and removing the second key-value pair from the second cache.
8. A countdown device, characterized in that, Including: Obtaining a countdown module for obtaining a countdown object and a countdown time, generating a first key-value pair based on the countdown object and the countdown time, and displaying the countdown time; Creating a countdown task module for creating a corresponding countdown task according to the countdown object and generating a second key-value pair based on the countdown object and the countdown task; Executing the countdown module for calling the thread pool to obtain the countdown task within a set time period, performing the countdown task according to the first key-value pair and the second key-value pair to update the countdown time and display it; Wherein, the countdown object is an entity that associates the graphical interface with the countdown logic, and the countdown task is a logical entity for establishing the countdown time and maintaining the key-value pair for each countdown object within the system.
9. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein, When the processor executes the program, it implements the steps of the countdown method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, wherein, When the computer program is executed by the processor, it implements the steps of the countdown method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Distributed timing system based on MongoDB
CN107608662A
Data updating method and device, computer equipment and storage medium
CN111339460A