Rule list acquisition method and device, equipment and storage medium
By recording the version mark value of the rule list in the global variable and updating the copy mark value in the thread variable, ensuring that the version obtained when the rule list is called multiple times in the same thread is consistent, solving the inconsistency caused by dynamic update of the rule list and avoiding task execution errors.
Patent Information
- Application Number
- CN202311443343.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-01
- Publication Date
- 2025-05-06
AI Technical Summary
In a business system, when the same thread task calls the rule list multiple times, inconsistency may occur due to dynamic update of the rule list, resulting in incorrect task execution results.
By recording the first version mark value of the rule list in the global variable, and obtaining the mark value when the rule execution instruction is first triggered, the corresponding target rule list is obtained, and the second version mark value in the thread variable is updated. After that, when the rule execution instruction is triggered again, the target rule list is obtained using the second version mark value to ensure that the obtained rule list is the same version.
Ensure that during the task execution process of the same thread, the obtained target rule list is the same version, and avoid errors in the task execution results caused by inconsistent rules lists of multiple calls.
Smart Images

Figure CN119938236A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a method, apparatus, device and storage medium for obtaining a rule list. Background Art
[0002] At present, for some business systems with frequently changing business requirements, the business logic can be separated from them, configured into a rule list, and the rule list can be dynamically updated. During the operation of the application corresponding to the business system, when a thread task needs to call the rule list, the rule list can be obtained from a predetermined data source (database or local), and then the corresponding rules in the rule list can be executed (for example, data judgment or semantic judgment).
[0003] However, in the process of implementing the present invention, it is found that there are at least the following problems in the prior art: during the operation of the application, for the same thread task, it may be necessary to call the rule list multiple times. Since the rule list may be updated at any time during the execution of the thread task, the rule lists called multiple times may be inconsistent. This may cause errors in the execution results of the thread task. Summary of the invention
[0004] The embodiments of the present invention provide a method, apparatus, device and storage medium for obtaining a rule list, which can ensure that in the process of executing a task of the same thread, the target rule lists obtained are all rule lists of the same version, thereby avoiding errors in task execution results caused by inconsistent rule lists called multiple times.
[0005] In a first aspect, an embodiment of the present invention provides a method for obtaining a rule list, which may include: in response to a task start instruction, starting to execute the current task of the current thread; in the process of executing the current task, when the rule execution instruction is triggered for the first time, obtaining a first version tag value in the global variable for each thread, and obtaining a corresponding target rule list based on the first version tag value, and updating a second version tag value in the thread variable for the current thread based on the first version tag value; when the rule execution instruction is triggered again, obtaining a second version tag value, and obtaining a corresponding target rule list based on the second version tag value.
[0006] In a second aspect, an embodiment of the present invention further provides a device for obtaining a rule list, which may include: an execution module and an acquisition module;
[0007] Specifically, the execution module is used to start executing the current task of the current thread in response to the task start instruction;
[0008] an acquisition module, used to acquire, in the process of executing the current task, a first version tag value in a global variable for each thread when a rule execution instruction is triggered for the first time, acquire a corresponding target rule list based on the first version tag value, and update a second version tag value in a thread variable for the current thread based on the first version tag value;
[0009] The acquisition module is used to acquire the second version tag value when the rule execution instruction is triggered again, and acquire the corresponding target rule list based on the second version tag value.
[0010] In a third aspect, an embodiment of the present invention provides a device for obtaining a rule list, and the device for obtaining a rule list includes:
[0011] one or more processors;
[0012] A memory for storing one or more programs;
[0013] When the one or more programs are executed by the one or more processors, the one or more processors implement the method for obtaining a rule list as provided in any embodiment of the present invention.
[0014] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method for obtaining a rule list as provided in any embodiment of the present invention.
[0015] The embodiments of the above invention have the following advantages or beneficial effects:
[0016] In the technical solution provided by the embodiment of the present invention, a global variable for each thread of the application can be predetermined, and the global variable can be used to record the version of the rule list updated most recently (i.e., the first version tag value in the embodiment of the present invention). Then, in the process of executing the current task of the current thread, if the rule execution instruction is triggered for the first time (i.e., there is a need to obtain the rule list for the first time), the first version tag value recorded in the global variable at this time can be obtained, and the corresponding target rule list can be obtained based on the first version tag value; and the second version tag value in the thread variable for the current thread can also be updated based on the first version tag value, that is, the first version tag value recorded in the global variable at this time is assigned to the thread variable of the current thread. Afterwards, if the rule execution instruction is triggered again, the second version tag value can be obtained, and the corresponding target rule list can be obtained based on the second version tag value. Since the thread variable of the current thread is private to the thread, the second version tag value in the thread variable of the current thread remains unchanged during the execution of the current task. Then, after the rule execution instruction is triggered for the first time, no matter how many times the rule execution instruction is triggered, the target rule list obtained based on the second version tag value is the same version of the rule list. Furthermore, since the second version tag value in the thread variable of the current thread is updated based on the first version tag value recorded in the global variable when the rule execution instruction is first triggered, the second version tag value is consistent with the first version tag value referenced by the target rule list obtained when the rule execution instruction is first triggered. Then, the target rule list obtained based on the second version tag value is also the same version of the rule list as the target rule list obtained when the rule execution instruction is first triggered. Therefore, in the process of executing the current task of the current thread, the target rule list obtained each time is the same version of the rule list. It can be seen that based on the technical solution provided by the embodiment of the present invention, it can be ensured that in the process of executing a task of the same thread, the target rule lists obtained are all the same version of the rule list, thereby avoiding errors in the task execution results caused by inconsistent rule lists called multiple times. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a flowchart of a method for obtaining a rule list provided by an embodiment of the present invention;
[0018] Figure 2 is a flowchart of another method for obtaining a rule list provided by an embodiment of the present invention;
[0019] Figure 3 It is a schematic diagram of a processing flow of a thread task in the prior art;
[0020] Figure 4 It is a schematic diagram of a processing flow of a thread task provided by an embodiment of the present invention;
[0021] Figure 5 It is a structural diagram of a device for obtaining a rule list provided by an embodiment of the present invention;
[0022] Figure 6 It is a structural diagram of a rule list acquisition device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0023] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0024] The term "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0025] In addition, the terms "including" and "having" and any variations thereof mentioned in the description of the embodiments of the present invention are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device including a series of steps or units is not limited to the listed steps or units, but may optionally include other steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.
[0026] It should be noted that, in the embodiments of the present invention, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of the present invention should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0027] In the description of the embodiments of the present invention, unless otherwise specified, “plurality” or “each” means two or more than two.
[0028] Figure 1A flowchart of a method for obtaining a rule list provided in an embodiment of the present invention, the method can be applicable to an application scenario in which a rule list of a business system with multiple threads is dynamically updated. The method can be executed by a device for obtaining a rule list provided in an embodiment of the present invention, and the device can be implemented in software and / or hardware and integrated in a device for obtaining a rule list. In a possible implementation, the device for obtaining a rule list can be an execution device of an application corresponding to the business system, for example, it can be an embedded terminal of the application. In addition, in an embodiment of the present invention, the processing process for each thread is exactly the same, and in the following description of an embodiment of the present invention, the processing process for one thread will be used as an example for explanation.
[0029] like Figure 1 As shown, the method for obtaining a rule list provided in an embodiment of the present invention specifically includes the following steps:
[0030] S110 . In response to a task start instruction, start executing the current task of the current thread.
[0031] A thread is the smallest unit that an operating system can schedule operations on. It is contained in a process and is the actual operating unit in the process. A thread refers to a single sequential control flow in a process. Multiple threads can run concurrently in a process, and these threads can execute different tasks in parallel. The method for obtaining a rule list provided in an embodiment of the present invention can be applied to an application scenario in which a rule list of a business system with multiple threads is dynamically updated.
[0032] For example, in a possible business scenario, in order to identify different types of security vulnerabilities, a thread can be determined for each of the different types of security vulnerability identification processes, and these threads can be executed in parallel to improve the efficiency of identifying security vulnerabilities. For example, multiple threads can be determined for possible cross-site scripting (XSS) vulnerabilities, unauthorized access vulnerabilities, cross-origin resource sharing (CORS) vulnerabilities, and structured query language (SQL) injection vulnerabilities that may occur in the business system.
[0033] In another possible business scenario, the business system may be an e-commerce system. When a user places an order in an application corresponding to the e-commerce system, the ordering methods (for example, the ordering methods may include single item ordering, single item batch ordering, multiple item single item ordering, and multiple item batch ordering) may be different. For different ordering methods, a thread may be determined respectively, and these threads may be executed in parallel to improve the processing efficiency of the order.
[0034] It is understandable that, in practical applications, the method for obtaining a rule list provided in the embodiment of the present invention may also be applied to other business scenarios, and the embodiment of the present invention does not limit this.
[0035] The rule list may be a rule set including multiple business rules, which is used for data judgment or semantic judgment.
[0036] In a possible implementation, the task start instruction may be an instruction that is automatically triggered after adding the data to be processed to the current thread. The task content of the current task of the current thread may be to process the data to be processed, and the rule list may need to be called multiple times during the processing. Exemplarily, taking the business scenario of identifying security vulnerabilities as an example, the current thread may be a thread determined by the identification process for unauthorized vulnerabilities, and the data to be processed may include fields to be identified (for example, fields corresponding to user accounts), then the task start instruction may be automatically triggered after the data to be processed flows into the current thread. After the task start instruction is triggered, the fields to be identified may be processed, and the processing process may need to call the rule list corresponding to the unauthorized vulnerability multiple times (for example, the rule list corresponding to the unauthorized vulnerability includes departments currently allowed to access the business system, operating projects currently allowed to access, etc.), and the timing of calling the rule list corresponding to the unauthorized vulnerability is recorded in the processing logic of the task processing process. When the rule list corresponding to the unauthorized vulnerability is called for the first time, it can be determined based on the rule list corresponding to the unauthorized vulnerability whether the user account belongs to the department currently allowed to access. If not, it can be determined that an unauthorized vulnerability has been identified and the current task should be stopped. If yes, the current task can be continued. When the rule list corresponding to the unauthorized vulnerability is called for the second time, it can be determined based on the rule list corresponding to the unauthorized vulnerability whether the operating project to which the user account belongs belongs to the operating project currently allowed to access. If not, it can be determined that an unauthorized vulnerability has been identified and the current task should be stopped. If yes, the current task can be continued.
[0037] S120. During the execution of the current task, when the rule execution instruction is triggered for the first time, the first version tag value in the global variable for each thread is obtained, and the corresponding target rule list is obtained based on the first version tag value, and the second version tag value in the thread variable for the current thread is updated based on the first version tag value.
[0038] In one possible implementation, the timing of each call to the rule list is recorded in the processing logic of the current task. In the process of executing the current task, when the timing of calling the rule list for the first time is reached, the rule execution instruction is automatically triggered for the first time, and when the timing of calling the rule list again is reached, the rule execution instruction is automatically triggered again. Exemplarily, the timing of calling the rule list for the first time / again can be the corresponding moment when a certain data is acquired, or it can be the corresponding moment when the processing of a certain data is completed. Taking the current thread corresponding to the unauthorized vulnerability as an example, the timing of calling the rule list twice is recorded in the processing logic of the current task. The first time to call the rule list is the moment when the parsing of the field to be identified is completed. After the parsing of the field to be identified is completed, the rule execution instruction will be triggered for the first time; the second time to call the rule list is the corresponding moment when it is determined that no security vulnerability has been identified after the rule execution instruction is triggered for the first time.
[0039] A global variable may be a unique data parameter that is globally visible to each thread in a multi-threaded scenario. In an embodiment of the present invention, a global variable for each thread may be predetermined, and the global variable may be used to record a first version tag value, and the first version tag value may be used to represent the version of the most recently updated rule list. Taking Java (a computer language) as a task processing language as an example, a constant may be first defined in the Java virtual machine, and then the constant may be modified by volatile (with visibility to be accessed by multiple threads), thereby obtaining a global variable that is globally visible to each thread.
[0040] Since the first version tag value recorded in the global variable can be used to represent the version of the most recently updated rule list, when the rule execution instruction is triggered for the first time, the target rule list obtained based on the first version tag value recorded in the global variable at this time is also the latest rule list. If the rule list is updated, then after the update, as long as a new task is started, the new task can be executed based on the latest rule list, so that each update to the rule list can be ensured to be effective.
[0041] In addition, when the rule execution instruction is triggered for the first time, the first version tag value obtained at this time can also be assigned to the thread variable of the current thread. In this way, the second version tag value in the thread variable of the current thread is consistent with the first version tag value referenced by the target rule list obtained when the rule execution instruction is triggered for the first time. Then, the target rule list obtained based on the second version tag value and the target rule list obtained when the rule execution instruction is triggered for the first time are the same version of the rule list.
[0042] Thread variables can be understood as private or local information of a thread. Taking Java as the task processing language as an example, it can be implemented through ThreadLocal (a thread binding mechanism in Java). The thread variables of the current thread are only visible to the current thread and are isolated from other threads, that is, the thread variables of the current thread are variables unique to the current thread. In an embodiment of the present invention, a thread variable is equivalent to a copy of a global variable in the current thread, that is, the current thread only obtains the global variable once and assigns it to the thread variable during the processing of the current task. The subsequent processing process is based on the thread variable to obtain the rule list. In this way, it can be ensured that the target rule list obtained for the first time based on the global variable can be read repeatedly.
[0043] S130. When the rule execution instruction is triggered again, obtain a second version mark value, and obtain a corresponding target rule list based on the second version mark value.
[0044] Since the thread variable of the current thread is private to the thread, the second version tag value in the thread variable of the current thread remains unchanged during the execution of the current task. Then, after the rule execution instruction is triggered for the first time, no matter how many times the rule execution instruction is triggered, the target rule list obtained based on the second version tag value is the rule list of the same version.
[0045] In one possible implementation, each time a rule execution instruction is triggered, it can be determined whether a second version mark value is recorded in the thread variable of the current thread. If it is determined that a second version mark value is recorded in the thread variable of the current thread, it can be determined that the rule execution instruction triggered this time is not the rule execution instruction triggered for the first time. In this case, the corresponding target rule list can be directly obtained based on the second version mark value recorded in the thread variable of the current thread. On the contrary, if it is determined that the thread variable of the current thread does not record the second version mark value, it can be determined that the rule execution instruction triggered this time is the rule execution instruction triggered for the first time. In this case, the first version mark value recorded in the global variable can be obtained from the global variable, and then the first version mark value is assigned to the thread variable of the current thread, and the corresponding target rule list is obtained based on the first version mark value.
[0046] Optionally, after obtaining the corresponding target rule list based on the first version tag value, the rule list acquisition method provided by the embodiment of the present invention may further include: parsing the acquired target rule list through the rule engine component to execute the rule execution subtask corresponding to the rule execution instruction triggered for the first time; after obtaining the corresponding target rule list based on the second version tag value, the rule list acquisition method provided by the embodiment of the present invention may further include: parsing the acquired target rule list through the rule engine component to execute the rule execution subtask corresponding to the rule execution instruction triggered again.
[0047] Among them, the rule engine component is a component embedded in the application. Based on the rule engine component, the business logic can be separated from the application code, and the relevant code of the business logic can be written using predefined semantic modules. The rule engine component can receive the data to be processed (for example, the field to be identified), and can parse each rule in the rule list to match the data to be processed with the rules, and can process the data to be processed based on the matched rules to obtain the processing results. Exemplarily, the rule engine component can be a component implemented based on qlExpress, aviator (two commonly used engines), etc.
[0048] In the method for obtaining a rule list provided in an embodiment of the present invention, a global variable for each thread of an application program can be predetermined, and the global variable can be used to record the version of the rule list updated most recently (i.e., the first version tag value in the embodiment of the present invention). Then, in the process of executing the current task of the current thread, if the rule execution instruction is triggered for the first time (i.e., there is a need to obtain the rule list for the first time), the first version tag value recorded in the global variable at this time can be obtained, and the corresponding target rule list can be obtained based on the first version tag value; and the second version tag value in the thread variable for the current thread can also be updated based on the first version tag value, that is, the first version tag value recorded in the global variable at this time is assigned to the thread variable of the current thread. Afterwards, if the rule execution instruction is triggered again, the second version tag value can be obtained, and the corresponding target rule list can be obtained based on the second version tag value. Since the thread variable of the current thread is private to the thread, the second version tag value in the thread variable of the current thread remains unchanged during the execution of the current task. Then, after the rule execution instruction is triggered for the first time, no matter how many times the rule execution instruction is triggered, the target rule list obtained based on the second version tag value is a rule list of the same version. Furthermore, since the second version tag value in the thread variable of the current thread is updated based on the first version tag value recorded in the global variable when the rule execution instruction is first triggered, the second version tag value is consistent with the first version tag value referenced by the target rule list obtained when the rule execution instruction is first triggered. Then, the target rule list obtained based on the second version tag value is also the same version of the rule list as the target rule list obtained when the rule execution instruction is first triggered. Therefore, in the process of executing the current task of the current thread, the target rule list obtained each time is the same version of the rule list. It can be seen that the method for obtaining the rule list provided in the embodiment of the present invention can ensure that in the process of executing a task of the same thread, the target rule lists obtained are all the same version of the rule list, thereby avoiding errors in the task execution results caused by inconsistent rule lists called multiple times.
[0049] In another embodiment, the above-mentioned "obtaining the corresponding target rule list based on the first version tag value" may include: based on the first version tag value, searching for the target rule list corresponding to the first version tag value in a predetermined collection class container; the above-mentioned "obtaining the corresponding target rule list based on the second version tag value" may include: based on the second version tag value, searching for the target rule list corresponding to the second version tag value in a collection class container.
[0050] Reference Figure 2 , is a flow chart of another method for obtaining a rule list provided in an embodiment of the present invention. The method in this embodiment can be combined with various optional solutions in the method for obtaining a rule list provided in the previous embodiment, and the method for obtaining a rule list provided in the previous embodiment is further optimized. Figure 2 As shown, the specific steps include:
[0051] S210 . In response to a task start instruction, start executing the current task of the current thread.
[0052] S220. In the process of executing the current task, when the rule execution instruction is triggered for the first time, the first version tag value in the global variable for each thread is obtained, and based on the first version tag value, a target rule list corresponding to the first version tag value is searched in a predetermined collection class container, and the second version tag value in the thread variable for the current thread is updated based on the first version tag value.
[0053] The method for obtaining a rule list provided in the embodiment of the present invention may use Java as a task processing language. Correspondingly, a collection class container may be used as a cache pool of the rule list to store different versions of the rule list.
[0054] In one possible implementation, a ConcurrentHashMap (a container implementation in Java for storing key-value information) collection can be used as a cache pool for the rule list. The key of the ConcurrentHashMap collection is the version tag value, and the content is a list of rules corresponding to different version tag values. Using the ConcurrentHashMap collection as the cache pool for the rule list can support high concurrency and ensure thread safety. It is understandable that in actual applications, other types of collection containers that can support high concurrency and ensure thread safety can also be used as the cache pool for the rule list, and the embodiments of the present invention do not limit this.
[0055] S230: When the rule execution instruction is triggered again, obtain the second version tag value, and search for a target rule list corresponding to the second version tag value in a collection class container based on the second version tag value.
[0056] For example, after obtaining the first version tag value in the global variable for each thread, the corresponding target rule list can be obtained from the collection class container through the get method of ConcurrentHashMap based on the first version tag value. Similarly, after obtaining the second version tag value, the corresponding target rule list can be obtained from the collection class container through the get method of ConcurrentHashMap based on the second version tag value.
[0057] Optionally, the method for obtaining a rule list provided in an embodiment of the present invention may further include: when a rule list update instruction is detected, updating the first rule list corresponding to the rule list update instruction to a collection class container, and generating a version tag value for the first rule list based on preset rules, and updating the first version tag value based on the version tag value of the first rule list.
[0058] In one possible implementation, an embodiment of the present invention may periodically poll a rule list stored at a data source (database or local) through a sub-thread. If a polling process detects that the rule list stored at the data source has changed, a rule list update instruction may be triggered. The rule list update instruction may carry the latest version of the rule list stored at the data source.
[0059] In another possible implementation, when an external party (external application or external plug-in, etc.) updates the rule list stored in the data source, an update message may be sent to the application to notify the application that the rule list stored in the data source has changed. At this time, the application may passively trigger the rule list update instruction and obtain the latest version of the rule list stored in the data source from the data source.
[0060] The preset rule may be a predetermined rule for generating a version tag value. Exemplarily, the preset rule may be a randomly generated unique thread pointer as a version tag value of a rule list. In a possible implementation, the version tag value in an embodiment of the present invention may be a Universally Unique Identifier (UUID) code.
[0061] It can be seen that in the embodiment of the present invention, in addition to the main logic thread, an auxiliary thread is independently started to periodically pull the latest rule list according to business needs (or passively obtain the latest rule list based on the received update message), and save each acquired rule list as a complete copy in the cache pool. In addition, while saving the rule list to the cache pool, a corresponding version tag value can be generated for the updated rule list, and the version tag value can be updated to the global variable. In this way, when a new task is started, the latest version of the rule list can be obtained from the cache pool based on the latest first version tag value stored in the global variable, without the need to restart the service release code type, and each rule change can take effect.
[0062] Optionally, the method for obtaining a rule list provided in an embodiment of the present invention further includes: when an application startup instruction is detected, obtaining a second rule list that was most recently updated and updating the second rule list to a collection class container, and generating a version tag value for the second rule list based on preset rules, and updating the first version tag value based on the version tag value of the second rule list.
[0063] The application start instruction may be an instruction detected in response to a trigger operation performed by a user on an icon of an application program.
[0064] In the embodiment of the present invention, in order to ensure that the cache pool stores the most recently updated second rule list before the application takes over the business processing task, the most recently updated second rule list stored in the data source can be fully loaded into the collection class container when the application is started. The specific process of updating the second rule list to the collection class container and the operation process after updating to the collection class container are similar to the aforementioned processing process for the rule list update instruction, and can refer to the aforementioned related description, which will not be repeated here.
[0065] Optionally, the method for obtaining a rule list provided by an embodiment of the present invention further includes: for each rule list stored in the collection container, when it is determined that the storage time of the current rule list meets a preset condition, deleting the current rule list stored in the collection container.
[0066] The preset condition may be a predetermined condition for determining whether the storage time of each rule list has expired. In a possible implementation, when the rule list is stored in a collection container, a timestamp may be added to the rule list to record the storage time of the rule list in the collection container. When the storage time of the rule list in the collection container exceeds a pre-configured maximum life cycle, the rule list may be deleted from the collection container.
[0067] In another possible implementation, the order of storage time of each rule list in the collection container can be recorded. When the number of rule lists stored in the collection container reaches a pre-configured maximum number, the rule list with the earliest storage time can be deleted from the collection container in a first-in-first-out manner.
[0068] It can be seen that in the embodiment of the present invention, each rule list stored in the cache pool can also be managed by time limit, and the rule list whose storage time meets the preset conditions can be cleaned up and recycled, so that storage space can be saved.
[0069] Optionally, for each rule list stored in a collection-type container, when it is determined that the storage time of the current rule list meets a preset condition, deleting the current rule list stored in the collection-type container may include: for each rule list, when it is determined that the storage time of the current rule list meets the preset condition, determining whether the current rule list is associated with a thread task; when it is determined that the current rule list is not associated with a thread task, deleting the current rule list stored in the collection-type container.
[0070] When the storage time of the current rule list meets the preset conditions, there may be a situation where the current rule list is associated with a thread task. In order to ensure that the thread task associated with the current rule list can be executed normally, in the embodiment of the present invention, for the rule list whose storage time meets the preset conditions, before cleaning it, it can be determined whether it is associated with a thread task. If it is not associated with a thread task, the rule list can be deleted; if it is associated with a thread task, the rule list can be deleted after the execution of the associated thread task is completed.
[0071] In a possible implementation, each rule list exists as an object in the cache pool, corresponding to a unique identity address. The identity address has a reference relationship in the Java virtual machine, and whether the current rule list is associated with a thread task can be determined based on the reference relationship of the identity address.
[0072] Optionally, the method for obtaining a rule list provided by an embodiment of the present invention further includes: when it is determined that the current task has been completed, initializing and resetting the second version mark value.
[0073] Exemplarily, the initialization and resetting operation on the second version mark value may be a deletion operation on the second version mark value in the thread variable of the current thread.
[0074] In an embodiment of the present invention, after the current thread completes executing the current task, the rule pointer data (i.e., the second version mark value) in the thread variable of the current thread can be cleaned up. In this way, it can be ensured that when the current thread executes the next task, the second version mark value can be re-obtained from the global variable to obtain the latest version of the rule list.
[0075] In an embodiment of the present invention, based on the above-mentioned embodiment, a collection-type container can be pre-determined as a cache pool for storing different versions of rule lists (that is, rule lists corresponding to different version tag values). In this way, in the process of executing the current task of the current thread, when the rule list stored at the data source changes, since the cache pool stores a version of the rule list before the change, and the thread variable of the current thread records the version tag value corresponding to the version of the rule list before the change (that is, the second version tag value in the embodiment of the present invention), based on the second version tag value recorded in the thread variable of the current thread, the version of the rule list before the change can be accurately found in the cache pool. It can be seen that the embodiment of the present invention can ensure that the rule list can be repeatedly readable without affecting the dynamic update process of the rule list at the data source by setting a cache pool to store different versions of the rule list.
[0076] It should be noted that the method for obtaining the rule list proposed in the embodiment of the present invention and the aforementioned embodiment belong to the same inventive concept. The technical details not fully described in this embodiment can be referred to the aforementioned embodiment, and the beneficial effects of the aforementioned embodiment are also applicable to this embodiment.
[0077] In order to more clearly describe the technical effect of the method for obtaining a rule list provided in an embodiment of the present invention, a specific example is used in the prior art and is compared with the application in an embodiment of the present invention.
[0078] Reference Figure 3 , is a schematic diagram of the processing flow of thread tasks in the prior art. Figure 3As shown, there is a current task being executed in the current thread. During the execution of the current task, the rule list needs to be read twice from the database. When the rule execution instruction is triggered for the first time, the rule list stored in the database is rule list 1, so the rule list obtained when the rule execution instruction is triggered for the first time is rule list 1. After the rule execution instruction is triggered for the first time and before the rule execution instruction is triggered for the second time, the rule list stored in the database is changed to rule list 2. Then, when the rule execution instruction is triggered for the second time, rule list 2 is obtained. In this way, due to the inconsistency of the rule lists obtained twice, business anomalies may occur. Exemplarily, taking the business system as an e-commerce system, for the thread corresponding to the ordering method for placing a single order for multiple items or placing a batch order for multiple items, the rule list contains rules on how to split the items in the order and how to mark the split orders. When processing the order task, the thread needs to call the rule list twice to split the order and mark it respectively. However, there may be some other processing logic between the two steps of splitting the order and labeling. During this period, if the rule list stored in the database is changed, the rule list referenced by the two subtasks of splitting the order and labeling will be inconsistent. This will cause the split orders to be unable to be shipped out as required due to incorrect marking.
[0079] Reference Figure 4 , is a schematic diagram of a thread task processing flow provided by an embodiment of the present invention. Figure 4As shown, when the application is started, the rule list 1 currently stored in the database can be saved to the cache pool, and the thread pointer 1 (i.e., the version tag value) corresponding to the rule list 1 can be generated, and the thread pointer 1 can be assigned to the global variable. If a current task is added to the current thread, and the current task needs to read the rule list twice from the database during execution, then when the rule execution instruction is triggered for the first time, the thread pointer 1 recorded in the global variable at this time can be obtained from the global variable, and the rule list 1 corresponding to the thread pointer 1 can be searched in the cache pool based on the thread pointer 1, and the thread pointer 1 can be assigned to the thread variable of the current thread; after the rule execution instruction is triggered for the first time and before the rule execution instruction is triggered for the second time, if the rule list stored in the database is changed to the rule list 2, the changed rule list 2 can be saved to the cache pool, and the thread pointer 2 corresponding to the rule list 2 can be generated, and the thread pointer 2 can be assigned to the global variable. When the rule execution instruction is triggered for the second time, the thread pointer 1 recorded in the thread variable of the current thread can be obtained, and the rule list 1 corresponding to the thread pointer 1 can be searched in the cache pool based on the thread pointer 1. It can be seen that although the rule list has changed during the task execution, for the current task of the current thread, the rule list obtained twice is consistent, and the change of the rule list has no impact on the normal processing flow of the business. Figure 3 and Figure 4 Only the key steps in the processing of thread tasks are shown, and it does not constitute a limitation on the processing of thread tasks.
[0080] From the above comparison, it can be seen that in the embodiment of the present invention, by improving the processing process of thread tasks in the prior art, the consistency of the rule list obtained when the current thread executes a task can be ensured, thereby ensuring the security of the application behavior and avoiding errors in task execution results caused by inconsistent rule lists called multiple times.
[0081] Figure 5 The schematic diagram of the structure of the apparatus for obtaining a rule list provided in an embodiment of the present invention includes: an execution module 510 and an acquisition module 520 .
[0082] Exemplarily, the execution module 510 may execute S110 in the above method embodiment, and the acquisition module 520 may execute S120 and S130 in the above method embodiment.
[0083] Specifically, the execution module 510 is used to start executing the current task of the current thread in response to the task start instruction;
[0084] The acquisition module 520 is used to acquire the first version tag value in the global variable for each thread when the rule execution instruction is triggered for the first time during the execution of the current task, acquire the corresponding target rule list based on the first version tag value, and update the second version tag value in the thread variable for the current thread based on the first version tag value;
[0085] The acquisition module 520 is used to acquire the second version mark value when the rule execution instruction is triggered again, and acquire the corresponding target rule list based on the second version mark value.
[0086] Optionally, in a possible implementation manner, the acquisition module 520 is specifically configured to:
[0087] In the process of executing the current task by the execution module 510, when the rule execution instruction is triggered for the first time, the first version tag value in the global variable for each thread is obtained, and based on the first version tag value, a target rule list corresponding to the first version tag value is searched in a predetermined collection class container, and the second version tag value in the thread variable for the current thread is updated based on the first version tag value;
[0088] When the rule execution instruction is triggered again, the second version tag value is obtained, and based on the second version tag value, a target rule list corresponding to the second version tag value is searched in the collection class container.
[0089] Optionally, in another possible implementation manner, the apparatus for obtaining a rule list provided in the embodiment of the present invention may further include an updating module;
[0090] An update module is used to update the first rule list corresponding to the rule list update instruction into a collection class container when a rule list update instruction is detected, generate a version mark value for the first rule list based on preset rules, and update the first version mark value based on the version mark value of the first rule list.
[0091] Optionally, in another possible implementation manner, the apparatus for obtaining a rule list provided in the embodiment of the present invention may further include an updating module;
[0092] The update module is used to obtain the most recently updated second rule list and update the second rule list to a collection class container when an application startup instruction is detected, generate a version tag value for the second rule list based on preset rules, and update the first version tag value based on the version tag value of the second rule list.
[0093] Optionally, in another possible implementation manner, the apparatus for obtaining a rule list provided in the embodiment of the present invention may further include a deletion module;
[0094] The deleting module is used for deleting the current rule list stored in the collection container when it is determined that the storage time of the current rule list meets the preset condition.
[0095] Optionally, in another possible implementation manner, the deletion module is specifically used to:
[0096] For each rule list, when it is determined that the storage time of the current rule list meets the preset condition, it is determined whether the current rule list is associated with a thread task;
[0097] When it is determined that the current rule list is not associated with a thread task, the current rule list stored in the collection class container is deleted.
[0098] Optionally, in another possible implementation, the execution module 510 is further configured to:
[0099] After obtaining the corresponding target rule list based on the first version tag value, the obtained target rule list is parsed by the rule engine component to execute the rule execution subtask corresponding to the rule execution instruction triggered for the first time;
[0100] After acquiring the corresponding target rule list based on the second version tag value, the acquired target rule list is parsed by the rule engine component to execute the rule execution subtask corresponding to the re-triggered rule execution instruction.
[0101] Optionally, in another possible implementation manner, the apparatus for obtaining a rule list provided in the embodiment of the present invention may further include an initialization module;
[0102] The initialization module is used to initialize and reset the second version mark value when it is determined that the current task has been completed.
[0103] The device for obtaining a rule list provided in an embodiment of the present invention belongs to the same inventive concept as the method for obtaining a rule list provided in the aforementioned embodiments. For details not fully described in the embodiment of the device for obtaining a rule list, reference can be made to the relevant contents of the aforementioned method embodiments, and the corresponding beneficial effects can also be referred to the beneficial effect analysis of the aforementioned method embodiments.
[0104] Figure 6 A schematic diagram of the structure of a device for obtaining a rule list provided in an embodiment of the present invention. Figure 6 A block diagram of an exemplary rule list acquisition device 12 suitable for implementing an embodiment of the present invention is shown.
[0105] Figure 6 The display of the rule list acquisition device 12 is only an example and should not bring any limitation to the function and scope of use of the embodiment of the present invention.
[0106] like Figure 6 As shown, the rule list acquisition device 12 is in the form of a general-purpose computing device. The components of the rule list acquisition device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).
[0107] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0108] The rule list acquisition device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the rule list acquisition device 12, including volatile and non-volatile media, removable and non-removable media.
[0109] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory (i.e., Figure 6 The rule list acquisition device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 6 not shown, usually called a "hard drive"). Although Figure 6 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.
[0110] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0111] The rule list acquisition device 12 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), may also communicate with one or more devices that enable a user to interact with the rule list acquisition device 12, and / or may communicate with any device that enables the rule list acquisition device 12 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed through an input / output (I / O) interface 22. Furthermore, the rule list acquisition device 12 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) through a network adapter 20. Figure 6 As shown, the network adapter 20 communicates with other modules of the rule list acquisition device 12 via the bus 18. It should be understood that although Figure 6 Not shown, other hardware and / or software modules may be used in conjunction with the rule list acquisition device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0112] The processing unit 16 executes various functional applications and data processing by running the program stored in the system memory 28, such as implementing the steps of a method for obtaining a rule list provided in an embodiment of the present invention, the method comprising: in response to a task start instruction, starting to execute the current task of the current thread; in the process of executing the current task, when the rule execution instruction is triggered for the first time, obtaining the first version tag value in the global variable for each thread, and obtaining the corresponding target rule list based on the first version tag value, and updating the second version tag value in the thread variable for the current thread based on the first version tag value; when the rule execution instruction is triggered again, obtaining the second version tag value, and obtaining the corresponding target rule list based on the second version tag value.
[0113] Of course, those skilled in the art can understand that the processor can also implement the technical solution of the method for obtaining the rule list provided in any embodiment of the present invention.
[0114] The present embodiment provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the program implements the steps of a method for obtaining a rule list as provided in the aforementioned embodiment of the present invention. The method includes: in response to a task start instruction, starting to execute the current task of the current thread; in the process of executing the current task, when the rule execution instruction is triggered for the first time, obtaining a first version tag value in a global variable for each thread, and obtaining a corresponding target rule list based on the first version tag value, and updating a second version tag value in a thread variable for the current thread based on the first version tag value; when the rule execution instruction is triggered again, obtaining a second version tag value, and obtaining a corresponding target rule list based on the second version tag value.
[0115] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0116] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0117] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0118] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or a rule list acquisition device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0119] It should be understood by those skilled in the art that the modules or steps of the present invention described above can be implemented by a general-purpose computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, optionally, they can be implemented by a program code executable by a computer device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0120] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for obtaining a rule list, characterized in that: The method comprises: In response to the task start instruction, start executing the current task of the current thread; In the process of executing the current task, when the rule execution instruction is triggered for the first time, a first version tag value in a global variable for each thread is obtained, and a corresponding target rule list is obtained based on the first version tag value, and a second version tag value in a thread variable for the current thread is updated based on the first version tag value; When the rule execution instruction is triggered again, the second version mark value is obtained, and the corresponding target rule list is obtained based on the second version mark value.
2. The method for obtaining a rule list according to claim 1, characterized in that: The acquiring a corresponding target rule list based on the first version tag value includes: Based on the first version tag value, searching for a target rule list corresponding to the first version tag value in a predetermined collection class container; The acquiring a corresponding target rule list based on the second version tag value includes: Based on the second version tag value, the target rule list corresponding to the second version tag value is searched in the collection class container.
3. The method for obtaining a rule list according to claim 2, characterized in that: The method further comprises: When a rule list update instruction is detected, the first rule list corresponding to the rule list update instruction is updated to the collection class container, and a version tag value for the first rule list is generated based on preset rules, and the first version tag value is updated based on the version tag value of the first rule list.
4. The method for obtaining a rule list according to claim 2, characterized in that: The method further comprises: When an application startup instruction is detected, the most recently updated second rule list is obtained and the second rule list is updated to the collection class container, and a version tag value for the second rule list is generated based on preset rules, and the first version tag value is updated based on the version tag value of the second rule list.
5. The method for obtaining a rule list according to claim 2, characterized in that: The method further comprises: For each rule list stored in the collection container, when it is determined that the storage time of the current rule list meets a preset condition, the current rule list stored in the collection container is deleted.
6. The method for obtaining a rule list according to claim 5, characterized in that: For each rule list stored in the collection container, when it is determined that the storage time of the current rule list meets a preset condition, deleting the current rule list stored in the collection container includes: For each of the rule lists, when it is determined that the storage time of the current rule list meets the preset condition, determining whether the current rule list is associated with a thread task; When it is determined that the current rule list is not associated with a thread task, the current rule list stored in the collection type container is deleted.
7. The method for obtaining a rule list according to claim 1, characterized in that: After acquiring the corresponding target rule list based on the first version tag value, the method further includes: parsing the acquired target rule list through a rule engine component to execute a rule execution subtask corresponding to the rule execution instruction triggered for the first time; After acquiring the corresponding target rule list based on the second version tag value, the method further includes: parsing the acquired target rule list through the rule engine component to execute a rule execution subtask corresponding to the re-triggered rule execution instruction.
8. The method for obtaining a rule list according to any one of claims 1 to 7, characterized in that: The method further comprises: When it is determined that the current task is completed, an initialization reset operation is performed on the second version mark value.
9. A device for obtaining a rule list, characterized in that: include: An execution module, used for starting to execute a current task of a current thread in response to a task start instruction; an acquisition module, configured to acquire, during the execution of the current task, a first version tag value in a global variable for each thread when a rule execution instruction is triggered for the first time, acquire a corresponding target rule list based on the first version tag value, and update a second version tag value in a thread variable for the current thread based on the first version tag value; The acquisition module is used to acquire the second version tag value when the rule execution instruction is triggered again, and acquire the corresponding target rule list based on the second version tag value.
10. A device for obtaining a rule list, characterized in that: The device for obtaining the rule list includes: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method for obtaining a rule list as described in any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for obtaining a rule list as described in any one of claims 1 to 8 is implemented.