Batch coupon issuance method and device
Through the thread pool to manage multi-threads and obtain coupon operation permissions in a queuing manner, it solves the problem of difficulty in controlling the upper limit of coupon collection when multi-thread batch issuance of coupons, achieves efficient coupon issuance without exceeding the quota, and ensures resource utilization and Data consistency.
Patent Information
- Application Number
- CN202010926825.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-07
- Publication Date
- 2024-10-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the bank's equity system, when using multi-threading to issue coupons in batches, it is difficult to control the upper limit of coupon collection, which may exceed the business budget, causing low efficiency and inability to effectively control.
Use the thread pool to configure the coupon data to be issued for multiple threads in the original database, and obtain operation permissions in a queuing manner based on the remaining coupon information in the cache database to ensure efficient coupon issuance while avoiding over-issuance of coupons.
It achieves the efficient issuance of coupons while avoiding the problem of coupons exceeding the business budget, ensuring that customers do not receive excess coupons, and improving resource utilization and consistency of data operations.
Smart Images

Figure CN111985977B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a batch coupon issuance method and device. Background Art
[0002] In the bank's equity system, it is necessary to give targeted coupons to specific customers (such as customers waiting for salary payment), and each type of coupon has a certain budget limit to set the upper limit of coupons. When issuing coupons in batches, these limiting factors will control it. If it is implemented in a single-threaded way, the coupon issuance speed will be slow and the efficiency will be low; if it is implemented in a multi-threaded way, although it can solve the problem of low coupon issuance efficiency, it will also encounter another type of problem. When multiple threads issue multiple coupons of the same type in batches at the same time, the upper limit of the coupons cannot be controlled, and eventually the business budget is exceeded, and coupons are issued in excess to customers. Summary of the invention
[0003] The embodiment of the present invention provides a batch coupon issuance method, which is used to ensure high-efficiency coupon issuance while avoiding coupon issuance exceeding the business budget, thereby issuing over-amount coupons to customers. The method includes:
[0004] Configure the coupon data to be sent for multiple threads in the original database through thread pool;
[0005] According to the remaining information of different types of coupons stored in the cache database, coupon issuance processing is performed on the coupon data to be issued in multiple threads;
[0006] When the remaining coupon information is accessed by multiple threads at the same time, the operation authority for the remaining coupon information is obtained in a queue manner.
[0007] Optionally, the method further includes:
[0008] When there are multiple pieces of data in the first preset thread that process the issuance of the same type of coupon data to be issued, after all the coupon data to be issued of the same type in the first preset thread are processed, the operation authority for the remaining coupon information is released.
[0009] Optionally, after releasing the operation authority for the remaining information of the coupon, the method further includes:
[0010] The first preset thread is popped out of the queue, and a thread ranked one row below the first preset line in the queue is enabled to obtain the operation authority for the remaining coupon information.
[0011] Optionally, the method further includes:
[0012] At preset time intervals, the remaining information of different types of coupons in the cache database is synchronized with the coupon data to be issued in the original database.
[0013] The embodiment of the present invention further provides a batch coupon issuing device, which is used to ensure high-efficiency coupon issuance while avoiding coupon issuance exceeding the business budget, thereby issuing over-amount coupons to customers. The device includes:
[0014] A data configuration module is used to configure the coupon data to be sent for multiple threads in the original database by means of a thread pool;
[0015] The coupon processing module is used to process the coupon data to be issued in multiple threads according to the remaining information of different types of coupons stored in the cache database;
[0016] The operation authority acquisition module is used to acquire the operation authority for the remaining coupon information in a queue manner when the remaining coupon information is accessed by multiple threads at the same time.
[0017] Optionally, the device further comprises:
[0018] The operation authority releasing module is used to release the operation authority for the remaining information of the coupon when multiple data in the first preset thread process the same type of coupon data to be issued, and after all the same type of coupon data to be issued in the first preset thread are processed.
[0019] Optionally, the device further comprises:
[0020] The operation authority processing module is used to pop the first preset thread out of the queue and enable the thread ranked one row below the first preset line in the queue to obtain the operation authority for the remaining information of the coupon.
[0021] Optionally, the device further comprises:
[0022] The data synchronization module is used to synchronize the remaining information of different types of coupons in the cache database with the data of coupons to be issued in the original database at preset intervals.
[0023] An embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the computer program.
[0024] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for executing the above method.
[0025] In an embodiment of the present invention, to-be-issued coupon data is configured for multiple threads in an original database by means of a thread pool, and coupon issuance processing is performed on the to-be-issued coupon data in multiple threads according to different types of remaining coupon information stored in a cache database. When the remaining coupon information is accessed by multiple threads at the same time, the operation authority for the remaining coupon information is obtained in a queuing manner, thereby ensuring efficient coupon issuance while avoiding coupon issuance exceeding the business budget, thereby overissuing coupons to customers. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0027] Figure 1 Flow chart of the batch coupon issuance method in an embodiment of the present invention;
[0028] Figure 2 It is a structural schematic diagram of a batch voucher issuing device in an embodiment of the present invention;
[0029] Figure 3 This is a specific example diagram of queuing to obtain the operation authority for the remaining information of coupons in an embodiment of the present invention;
[0030] Figure 4 This is an example diagram of a process of accessing the same type of coupons by multiple pieces of data in an embodiment of the present invention;
[0031] Figure 5 This is a specific example diagram of obtaining and releasing the operation rights of the remaining information of the operation coupons between multiple threads in an embodiment of the present invention;
[0032] Figure 6 It is a schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0033] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0034] In the bank's equity system, it is necessary to give targeted coupons to specific customers (such as customers waiting for salary payments), and each type of coupon will have a certain budget limit to set an upper limit for receiving. When issuing coupons in batches, these limiting factors will control it. If it is implemented in a single-threaded manner, the coupon issuance speed will be slow and the efficiency will be low. If it is implemented in a multi-threaded manner, although it can solve the problem of low coupon issuance efficiency, it will also encounter another type of problem. When multiple threads simultaneously issue multiple coupons of the same type in batches, the upper limit for receiving this coupon cannot be controlled, and ultimately the business budget is exceeded, and coupons are issued in excess to customers. In order to solve the above problems, an embodiment of the present invention provides a batch coupon issuance method.
[0035] Figure 1 A flow chart of a batch coupon issuance method provided by an embodiment of the present invention, such as Figure 1 As shown, the method includes:
[0036] Step 101: Configure the coupon data to be sent for multiple threads in the original database by means of a thread pool.
[0037] In specific implementation, when the business plans to promote a certain type of coupon, it is necessary to create the coupon data to be issued in the original database and set various restrictions on the coupon, including the upper limit of the coupon quota. After the coupon data to be issued is successfully established, the remaining coupon quota field is synchronized to the cache database. When the coupon is subsequently collected, only the remaining coupon quota data is extracted from the cache database for deduction.
[0038] In an embodiment, multithreading is managed using a thread pool, and parameters such as the number of threads and lifetime can be configured through a configuration file.
[0039] Step 102: According to the remaining information of different types of coupons stored in the cache database, coupon issuance processing is performed on the coupon data to be issued in multiple threads.
[0040] In specific implementation, after the data of coupons to be issued is successfully established, the business can send coupons to specific customers by uploading a large number of whitelist customer coupon files. After the whitelist customer coupon file is uploaded to the original database, the system processes this file through multiple threads. Each thread obtains the data block of the coupon file and processes the coupon data to be issued in the block one by one.
[0041] Step 103: When the remaining coupon information is accessed by multiple threads at the same time, the operation authority for the remaining coupon information is obtained in a queue manner.
[0042] When implementing it, Figure 3As shown in the figure, when each thread in multiple threads processes the coupon data to be issued, it needs to obtain the hot data of the remaining quota of coupons, that is, the remaining coupon information. The hot data may be accessed by multiple threads in parallel. Therefore, when the remaining quota of coupons needs to be operated, it is necessary to queue up in a first-in-first-out manner to obtain the operation lock permission of the remaining quota, that is, the operation permission. When the top thread obtains the permission to operate this hot data, the remaining quota is deducted and the remaining quota in the cache is updated. If the remaining quota is already 0, it cannot be updated to reject the customer's coupon collection business.
[0043] Depend on Figure 1 It can be seen that a batch coupon issuance method provided by an embodiment of the present invention configures coupon data to be issued for multiple threads in an original database by means of a thread pool, and performs coupon issuance processing on the coupon data to be issued in multiple threads according to different types of coupon remaining information stored in a cache database. When the coupon remaining information is accessed by multiple threads at the same time, the operation authority for the coupon remaining information is obtained in a queuing manner. While ensuring high-efficiency coupon issuance, it avoids issuing coupons in excess of the business budget, thereby overissuing coupons to customers.
[0044] In order to reduce resource consumption, the method further includes:
[0045] When there are multiple pieces of data in the first preset thread that process the issuance of the same type of coupon data to be issued, after all the coupon data to be issued of the same type in the first preset thread are processed, the operation authority for the remaining coupon information is released.
[0046] When implementing it, Figure 4 As shown in the figure, if each thread has multiple data that need to access the remaining quota of the same coupon, a counter can be set in the thread for the operation of accessing the remaining quota of the same coupon. If the counter is greater than zero, the thread will always have the lock permission for the remaining quota hot data until the counter is equal to zero before continuing to the next operation. In this way, it is guaranteed that the thread can exclusively hold the lock, and the permission will be released immediately once the thread business processing is completed.
[0047] Furthermore, after releasing the operation authority for the remaining information of the coupon, the method further includes:
[0048] The first preset thread is popped out of the queue, and a thread ranked one row below the first preset line in the queue is enabled to obtain the operation authority for the remaining coupon information.
[0049] When implementing it, Figure 5As shown, when the thread successfully deducts the remaining quota and the counter returns to zero, the operation lock permission for the remaining coupon quota can be released. At the same time, the thread pops out of the queue, and the next queued thread becomes the top thread, and continues to obtain the operation lock permission for the remaining coupon quota, that is, the operation permission.
[0050] In order to ensure that the remaining information of different types of coupons in the cache database is consistent with the to-be-issued coupon data in the original database, the method further includes:
[0051] At preset time intervals, the remaining information of different types of coupons in the cache database is synchronized with the coupon data to be issued in the original database.
[0052] In specific implementation, for example, the remaining information of different types of coupons in the cache database may be synchronized with the to-be-issued coupon data in the original database every 10 seconds.
[0053] The present invention is described below with a specific embodiment:
[0054] The coupon data to be issued are configured in thread 1, thread 2 and thread 3 for multi-thread processing, wherein thread 1 includes coupons of category A and coupons of category B, thread 2 includes multiple coupons of category B, and thread 3 includes multiple coupons of category C. When performing the coupon processing operation, thread 1 processes the coupons of category A, thread 2 processes the coupons of category B, and thread 3 processes the coupons of category C. In this process, the coupon processing is performed in a first-in-first-out queue to obtain the operation authority of the remaining coupon information. When thread 1 has processed all the coupons of category A, it places the coupons of category B after the coupons of category B in thread 2 for processing. When processing multiple coupons of category B in thread 2, multiple coupons of category B to be issued in thread 2 are processed in sequence until all the coupons of category B to be issued are processed, and then thread 3 is processed in the same way. In this process, as the coupon data to be issued is processed, the remaining information of different types of coupons in the cache database is also reduced accordingly, and the remaining information of different types of coupons in the cache database is synchronized with the coupon data to be issued in the original database at preset intervals.
[0055] Based on the same inventive concept, a batch coupon issuing device is also provided in the embodiments of the present invention, as described in the following embodiments. Since the principle of solving the problem by the batch coupon issuing device is similar to that of the batch coupon issuing method, the implementation of the batch coupon issuing device can refer to the implementation of the batch coupon issuing method, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0056] Figure 2 A schematic diagram of the structure of a batch coupon issuing device provided by an embodiment of the present invention is shown in FIG. Figure 2 As shown, the device comprises:
[0057] The data configuration module 201 is used to configure the coupon data to be sent for multiple threads in the original database by means of a thread pool;
[0058] The coupon issuing processing module 202 is used to process the coupon issuing data to be issued in multiple threads according to the remaining information of different types of coupons stored in the cache database;
[0059] The operation authority acquisition module 203 is used to acquire the operation authority for the remaining coupon information in a queue manner when the remaining coupon information is accessed by multiple threads at the same time.
[0060] In an embodiment of the present invention, the device further includes:
[0061] The operation authority releasing module is used to release the operation authority for the remaining information of the coupon when multiple data in the first preset thread process the same type of coupon data to be issued, and after all the same type of coupon data to be issued in the first preset thread are processed.
[0062] In an embodiment of the present invention, the device further includes:
[0063] The operation authority processing module is used to pop the first preset thread out of the queue and enable the thread ranked one row below the first preset line in the queue to obtain the operation authority for the remaining information of the coupon.
[0064] In an embodiment of the present invention, the device further includes:
[0065] The data synchronization module is used to synchronize the remaining information of different types of coupons in the cache database with the data of coupons to be issued in the original database at preset intervals.
[0066] In order to achieve the above object, according to another aspect of the present application, a computer device is also provided. Figure 6 As shown, the computer device includes a memory, a processor, a communication interface and a communication bus. A computer program that can be executed on the processor is stored in the memory. When the processor executes the computer program, the steps in the above-mentioned embodiment method are implemented.
[0067] The processor may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.
[0068] The memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer executable programs and units, such as the corresponding program units in the above method embodiments of the present invention. The processor executes various functional applications of the processor and works data processing by running the non-transitory software programs, instructions and modules stored in the memory, that is, implementing the method in the above method embodiments.
[0069] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the processor, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0070] The one or more units are stored in the memory, and when executed by the processor, the method in the above embodiment is performed.
[0071] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for executing the above method.
[0072] To summarize, the present invention configures coupon data to be issued for multiple threads in the original database by means of a thread pool, and performs coupon issuance processing on the coupon data to be issued in multiple threads according to different types of coupon remaining information stored in a cache database. When the coupon remaining information is accessed by multiple threads at the same time, the operation authority for the coupon remaining information is obtained in a queuing manner. While ensuring high-efficiency coupon issuance, it avoids issuing coupons in excess of the business budget, thereby overissuing coupons to customers.
[0073] In addition, when the hot data needs to be processed concurrently for uploading large data files, the financial system has high requirements for the accuracy of hot data. This solution can ensure the consistency of hot data operations during multi-threaded concurrency; this solution is used in situations where high data accuracy is required while also ensuring resource utilization and performance. At the same time, the present invention implements the situation where the same thread can process multiple times and reenter, avoiding the same thread repeatedly queuing to acquire and release locks to increase resource consumption, and can solve the situation where two threads may acquire locks for two data at the same time and wait for the other party to release the lock to wait in a loop.
[0074] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0075] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0076] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0077] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0078] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for issuing coupons in batches, characterized in that: include: Configure the coupon data to be sent for multiple threads in the original database through thread pool; According to the remaining information of different types of coupons stored in the cache database, coupon issuance processing is performed on the coupon data to be issued in multiple threads; When the remaining coupon information is accessed by multiple threads at the same time, the operation authority for the remaining coupon information is obtained in a queue manner; Also includes: When there are multiple data in the first preset thread that process the same type of coupon data to be issued, after all the same type of coupon data to be issued in the first preset thread are processed, the operation authority for the remaining coupon information is released; After releasing the operation authority for the remaining information of the coupon, the method further includes: Popping the first preset thread out of the queue, and allowing the thread next to the first preset thread in the queue to obtain the operation authority for the remaining coupon information; The thread pool is used to configure the coupon data to be sent for multiple threads in the original database, including: When the business plans to promote a certain type of coupon, the coupon data to be issued is established in the original database, and various restrictions on the coupon are set; According to the remaining information of different types of coupons stored in the cache database, coupon issuance processing is performed on the coupon data to be issued in multiple threads, including: After the data of coupons to be issued is successfully established, coupons can be issued to specific customers by uploading a large number of whitelist customer coupon collection files; By uploading a large number of whitelist customer coupon collection files, coupons can be issued to specific customers, including: After the whitelist customer coupon collection file is uploaded to the original database, the system processes this file through multiple threads. Each thread obtains the data block of the coupon collection file and processes the coupon data to be issued in the block one by one.
2. The method according to claim 1, characterized in that Also includes: At preset time intervals, the remaining information of different types of coupons in the cache database is synchronized with the coupon data to be issued in the original database.
3. A batch voucher issuing device, characterized in that: include: A data configuration module is used to configure the coupon data to be sent for multiple threads in the original database by means of a thread pool; The coupon processing module is used to process the coupon data to be issued in multiple threads according to the remaining information of different types of coupons stored in the cache database; An operation authority acquisition module, used for acquiring the operation authority for the remaining coupon information in a queue manner when the remaining coupon information is accessed by multiple threads at the same time; Also includes: An operation permission releasing module, for releasing the operation permission for the remaining information of the coupon after all the same type of coupon data to be issued in the first preset thread is processed when there are multiple pieces of data in the first preset thread for issuing coupons; An operation authority processing module, configured to pop the first preset thread out of a queue, and enable a thread next to the first preset thread in the queue to obtain operation authority for the remaining coupon information; Among them, the data configuration module is specifically used for: When a business plans to promote a certain type of coupon, it is necessary to create data on coupons to be issued in the original database and set various restrictions on the coupons; The voucher processing module is specifically used for: After the data of coupons to be issued is successfully established, coupons can be issued to specific customers by uploading a large number of whitelist customer coupon collection files; The voucher processing module is specifically used for: After the whitelist customer coupon collection file is uploaded to the original database, the system processes this file through multiple threads. Each thread obtains the data block of the coupon collection file and processes the coupon data to be issued in the block one by one.
4. The device according to claim 3, characterized in that Also includes: The data synchronization module is used to synchronize the remaining information of different types of coupons in the cache database with the data of coupons to be issued in the original database at preset intervals.
5. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 2 is implemented.
6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 2 is implemented.
Citation Information
Patent Citations
System and method for processing high-concurrency interactive data request
CN106204232A
Synchronization lock based multi-thread processing method, terminal and storage medium
CN107729129A
Discount coupon issuing control method and apparatus
CN107730064A
High concurrent activity interaction method
CN108090058A
Method and a device for providing coupon
CN108460621A
