Thread execution method and device, equipment and medium
By using the target decorator in asynchronous programming to pass and restore the thread context, the problem that asynchronous threads cannot pass the parent thread context is solved, which improves the security and efficiency of thread context propagation, and ensures the correctness and user experience of asynchronous tasks.
Patent Information
- Application Number
- CN202411669374.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-02-18
AI Technical Summary
In asynchronous programming, asynchronous threads cannot effectively pass and restore the context information of the parent thread, making it difficult to guarantee the consistency and correctness of operations.
The target decorator is controlled to obtain the target context object corresponding to the current task thread in the preset thread pool and set it in the target task thread, so that the target task thread can perform the corresponding thread tasks asynchronously using the information in the target context object.
Improves the security and efficiency of thread context propagation, ensures context consistency and correctness between asynchronous tasks, thereby improving the user experience.
Smart Images

Figure CN119473523A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a thread execution method, device, equipment and medium. Background Art
[0002] In modern software development, with the rapid development of the application scale and complexity of enterprise IT (Information Technology) systems, asynchronous programming has become a key technology for implementing efficient and responsive applications. Among them, asynchronous programming can improve the response speed of the program and avoid the program being in a blocked state. In asynchronous programming, an operation is split into multiple asynchronous tasks, which need to be executed in different threads. In order to ensure that the status and context information of the operation can be correctly transferred and restored between these tasks, thread context transfer is required.
[0003] Under normal circumstances, the context data of the parent thread in an asynchronous thread cannot be passed to the child thread. However, in some application scenarios, it is necessary to obtain the context information of the parent thread, such as user identity, request information and other important data, so that the consistency and correctness of the operation are guaranteed. In addition, user authentication information, transaction context or request identifier also needs to be shared and maintained in asynchronous tasks.
[0004] As can be seen from the above, how to improve the security and efficiency of thread context propagation during thread execution is a problem that needs to be solved urgently. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide a thread execution method, apparatus, device and medium, which can obtain a target context object corresponding to the current task thread in a preset thread pool by controlling a target decorator, and set the target context object in a target task thread, so that the target task thread can asynchronously execute the corresponding thread task using the information in the target context object, thereby improving the security of thread context propagation and the efficiency of thread context propagation. The specific scheme is as follows:
[0006] In a first aspect, the present application provides a thread execution method, comprising:
[0007] A target decorator corresponding to a preset thread pool is created based on user needs; the preset thread pool includes a plurality of task threads; the task threads are executed asynchronously;
[0008] Control the target decorator to obtain a target context object corresponding to the current task thread in the preset thread pool using a preset context acquisition method;
[0009] Control the target decorator to set the target context object in the target task thread using a preset setting method, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task; the target task thread is a task thread that has a sequence with the current task thread and has not been executed.
[0010] Optionally, the creating a target decorator corresponding to a preset thread pool based on user requirements includes:
[0011] Constructing the preset thread pool by using the preset thread pool construction algorithm in the preset interface;
[0012] The preset decorator setting method in the preset interface is utilized, and a target decorator corresponding to the preset thread pool is created based on user requirements.
[0013] Optionally, after creating a target decorator corresponding to a preset thread pool based on user requirements, the method further includes:
[0014] The thread tasks respectively corresponding to the several task threads in the preset thread pool are annotated using a first preset annotation method to support asynchronous calling of the several thread tasks.
[0015] Optionally, after controlling the target decorator to set the target context object in the target task thread using a preset setting method, the method further includes:
[0016] Annotating the plurality of thread tasks using a second preset annotation method so that the preset framework creates corresponding target task threads for the plurality of thread tasks respectively, and triggers the target task threads to asynchronously execute operations of corresponding thread tasks using information in the target context object;
[0017] The execution time of the first preset annotation method is earlier than the execution time of the second preset annotation method.
[0018] Optionally, before controlling the target decorator to obtain the target context object corresponding to the current task thread in the preset thread pool using a preset context acquisition method, the method further includes:
[0019] Creating a preset context management space corresponding to the preset thread pool;
[0020] The context objects corresponding to the plurality of task threads in the preset thread pool are stored in the preset context management space, so that the target decorator obtains the target context object corresponding to the current task thread in the preset thread pool from the preset context management space.
[0021] Optionally, after the controlling the target decorator to set the target context object in the target task thread using a preset setting method so that the target task thread asynchronously executes the corresponding thread task using the information in the target context object, the method further includes:
[0022] The target context object corresponding to the target task thread is cleared using a preset clearing method.
[0023] Optionally, the target decorator is DemoContextDecorator, the preset context acquisition method is a ThreadLocal algorithm, the preset setting method is a getContext() algorithm of SecurityContextHolder, and the target context object is SecurityContext.
[0024] In a second aspect, the present application provides a thread execution device, including:
[0025] A decorator creation module is used to create a target decorator corresponding to a preset thread pool based on user needs; the preset thread pool includes a number of task threads; the execution mode of the task thread is asynchronous execution;
[0026] A first decorator control module, used to control the target decorator to obtain a target context object corresponding to the current task thread in the preset thread pool by using a preset context acquisition method;
[0027] The second decorator control module is used to control the target decorator to set the target context object in the target task thread using a preset setting method, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task; the target task thread is a task thread that has a sequence with the current task thread and has not been executed.
[0028] In a third aspect, the present application provides an electronic device, including:
[0029] Memory, used to store computer programs;
[0030] The processor is used to execute the computer program to implement the aforementioned thread execution method.
[0031] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, wherein the computer program implements the aforementioned thread execution method when executed by a processor.
[0032] As can be seen from the above, before executing the thread, the present application needs to create a target decorator corresponding to the preset thread pool based on user needs; the preset thread pool includes several task threads; the execution mode of the task thread is asynchronous execution; the target decorator is controlled to obtain the target context object corresponding to the current task thread in the preset thread pool using the preset context acquisition method; the target decorator is controlled to set the target context object in the target task thread using the preset setting method, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task; the target task thread is a task thread that has a sequence with the current task thread and has not been executed. It can be seen from this that the present application obtains the target context object corresponding to the current task thread in the preset thread pool by controlling the target decorator, and sets the target context object in the target task thread, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task. In this way, the security of thread context propagation and the efficiency of thread context propagation are improved, thereby improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0034] Figure 1 A flow chart of a thread execution method disclosed in this application;
[0035] Figure 2 A structural flow chart of a thread execution device disclosed in this application;
[0036] Figure 3 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0037] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0038] In modern software development, with the rapid development of the application scale and complexity of enterprise IT systems, asynchronous programming has become a key technology for realizing efficient and responsive applications. In asynchronous programming, an operation is split into multiple asynchronous tasks, which need to be executed in different threads. In order to ensure that the status and context information of the operation can be correctly transferred and restored between these tasks, thread context transfer is required. To this end, the present application provides a thread execution method, which can obtain a target context object corresponding to the current task thread in a preset thread pool by controlling a target decorator, and set the target context object in a target task thread, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task, thereby improving the security of thread context propagation and the efficiency of thread context propagation.
[0039] See also Figure 1 As shown, an embodiment of the present invention discloses a thread execution method, including:
[0040] Step S11, creating a target decorator corresponding to a preset thread pool based on user needs; the preset thread pool includes a plurality of task threads; the task threads are executed asynchronously.
[0041] In this embodiment, it is necessary to use the SpringBoot framework (i.e., a framework used to simplify the initial construction and development process of new Spring applications) to build a task thread pool, and then establish a target decorator based on the task thread pool; wherein, the target decorator is a structural design pattern, and its function is to add new functions to an existing object without changing its structure, so that the target decorator can be used to enhance the beginning and end of the thread asynchronous execution method in the future, thereby achieving the purpose of asynchronous thread context transfer, wherein, in the embodiment of the present application, the above-mentioned existing object is a task thread pool.
[0042] In this embodiment, a decorator corresponding to a preset thread pool storing several asynchronous tasks is created based on user needs, so that the decorator can be used to enhance the beginning and end of the thread execution method, uniformly realize the transfer of context between threads, and ensure the consistency and correctness of the context, thereby further ensuring that the context information corresponding to each task thread will not be lost during the execution of asynchronous tasks, and at the same time, the logic and business logic are separated in the process of transferring context objects between threads. Specifically, the creation of a target decorator corresponding to a preset thread pool based on user needs may include: constructing the preset thread pool through the preset thread pool construction algorithm in the preset interface; using the preset decorator setting method in the preset interface, and creating a target decorator corresponding to the preset thread pool based on user needs.
[0043] It is worth mentioning that in the traditional synchronous programming model, each operation will block the execution of the program until the operation is completed. For this reason, the synchronous programming model may cause a decrease in computer processing performance when processing a large number of requests. For the asynchronous programming model, it allows the program to execute operations without waiting for them to complete, but can continue to use threads to perform other tasks, thereby improving the concurrency and responsiveness of the program and avoiding the waste of limited computer resources because the program is always in a blocked state. In one specific embodiment, asynchronous programming can use asynchronous I / O (input / output) in network programming to implement the function of concurrently processing multiple requests, thereby improving the performance and concurrent processing capabilities of the server. In another specific embodiment, asynchronous programming can realize the rendering and interaction of single-page applications in Web (World Wide Web, also known as the World Wide Web) development, thereby improving the user experience.
[0044] It is understandable that in asynchronous programming, an operation is split into multiple asynchronous tasks so that the multiple asynchronous tasks are executed asynchronously in different threads. To this end, in order to ensure that the status and context information of the current operation can be correctly transferred and restored between these asynchronous tasks, context transfer operations between threads are required; that is, user authentication information, transaction context or request identifiers need to be shared and maintained in asynchronous tasks in certain application scenarios. However, in asynchronous threads, the context data of the parent thread cannot be passed to the child thread asynchronous thread. In addition, thread context transfer is also critical for logging and monitoring systems to ensure that log information is associated with a specific request or transaction.
[0045] In this embodiment, it is first necessary to use the preset thread pool construction method to construct the task thread pool; for example, use the getAsyncExecutor method in AsyncConfigurer (i.e., an interface in the Spring framework, used to configure the relevant parameters of the asynchronous task executor), and construct the task thread pool based on the developer's needs, which is not specifically limited here. It is worth mentioning that after the task thread pool is constructed, it is necessary to use the preset decorator construction method and construct the target decorator based on the task thread pool, for example, implement the decorate method of TaskDecorator through DemoContextDecorator (i.e., demonstration text decorator).
[0046] It is worth mentioning that after creating the target decorator corresponding to the preset thread pool, the first annotation method needs to be used to annotate the task in order to enable the asynchronous method execution function in the Spring framework. That is, the function of the first annotation method is to inform the Spring framework that in the current application context, the developer hopes to use asynchronous methods to improve the concurrency and performance of the program, so that the Spring framework will not block the caller's thread. Specifically, after creating the target decorator corresponding to the preset thread pool based on user needs, it can also include: using the first preset annotation method to annotate the thread tasks corresponding to several of the task threads in the preset thread pool to support asynchronous calls of several of the thread tasks. In a specific embodiment, the first annotation method is the @EnableAsync annotation, and any method that can enable the asynchronous method execution function in the Spring framework is applicable to this embodiment, and is not specifically limited here.
[0047] Step S12: Control the target decorator to obtain a target context object corresponding to the current task thread in the preset thread pool by using a preset context acquisition method.
[0048] In this embodiment, after the target decorator is established, the context object of the current task thread can be obtained through the target decorator, so that each task thread can have its own independent context data without interfering with the data of other task threads. For example, the getContext() method in SecurityContextHolder is used to obtain the target context object SecurityContext corresponding to the current task thread, where the target context object includes but is not limited to user authentication information, user permissions, thread local variables, transaction context, security credentials, user session information, as well as the value of CPU registers, stack status, and thread control block.
[0049] It is worth mentioning that in a multi-threaded environment, each thread has its own context to avoid cross-data interference. Before controlling the target decorator to obtain the target context object corresponding to the current task thread in the preset thread pool, it is necessary to store the context object corresponding to the task thread in advance in the preset context management space corresponding to the preset thread pool, so as to subsequently control the target decorator to obtain the target context object corresponding to the current task thread from the preset context management space. Specifically, before controlling the target decorator to obtain the target context object corresponding to the current task thread in the preset thread pool using the preset context acquisition method, it may also include: creating a preset context management space corresponding to the preset thread pool; storing the context objects corresponding to several of the task threads in the preset thread pool in the preset context management space, so that the target decorator obtains the target context object corresponding to the current task thread in the preset thread pool from the preset context management space. Among them, the preset context acquisition method can be a ThreadLocal algorithm, which is not specifically limited here.
[0050] Step S13, controlling the target decorator to set the target context object in the target task thread using a preset setting method, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task; the target task thread is a task thread that has a sequence with the current task thread and has not been executed.
[0051] In this embodiment, after obtaining the target context object, the target context object needs to be set to the subtask thread using a preset setting method. The preset setting method may be the SecurityContextHolder.setContext() method, and the subtask thread is a task thread that has a sequential dependency relationship with the current task thread and has not been executed. That is, before the subtask thread is started, the target context object of the current task thread is obtained, and the target context object is set in the subtask thread.
[0052] Then, after the subtask thread obtains the target context object of the current task thread, it is necessary to use the second annotation method to annotate the task so that the Spring framework automatically creates a new task thread for the thread task in the background, thereby allowing the thread task to be executed asynchronously without blocking the task thread that executes the task; that is, after the task is annotated using the second annotation method, the Spring framework can implement the normal operation of passing context information in the asynchronous thread. Specifically, after the control of the target decorator uses the preset setting method to set the target context object in the target task thread, it can also include: using the second preset annotation method to annotate several of the thread tasks, so that the preset framework creates corresponding target task threads for several of the thread tasks respectively, and triggers the target task thread to use the information in the target context object to asynchronously execute the corresponding thread task operation; wherein the execution time of the first preset annotation method is earlier than the execution time of the second preset annotation method.
[0053] It is worth mentioning that after the task is annotated with the second annotation method, the subtask thread can use the information corresponding to the target context object of the current task thread to perform the task execution operation. In addition, the second annotation method can be an @Async method, which is not listed here one by one, and before using the @Async annotation, the @EnableAsync annotation must be added to the configuration class. That is, in the Spring framework, the @EnableAsync annotation method is used to enable support for asynchronous methods. When the @EnableAsync annotation method is used, the Spring framework will look for methods with the @Async annotation and execute these methods in a separate thread.
[0054] It is worth mentioning that after the subtask thread performs a task based on the content in the target context object, the target context object corresponding to the subtask thread needs to be cleared using a preset clearing method to protect the security of the data stored in the memory. Specifically, the control of the target decorator using a preset setting method to set the target context object in the target task thread so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task can also include: clearing the target context object corresponding to the target task thread using a preset clearing method to prevent memory leaks.
[0055] In a specific implementation, the preset clearing method may be the SecurityContextHolder.clearContext() method; it is worth mentioning that any method capable of securely clearing the target context object corresponding to the subtask thread is applicable to this embodiment, and they are not listed one by one here.
[0056] As can be seen from the above, before executing the thread, the present application needs to create a target decorator corresponding to the preset thread pool based on user needs; the preset thread pool includes several task threads; the execution mode of the task thread is asynchronous execution; the target decorator is controlled to obtain the target context object corresponding to the current task thread in the preset thread pool using the preset context acquisition method; the target decorator is controlled to set the target context object in the target task thread using the preset setting method, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task; the target task thread is a task thread that has a sequence with the current task thread and has not been executed. It can be seen from this that the present application obtains the target context object corresponding to the current task thread in the preset thread pool by controlling the target decorator, and sets the target context object in the target task thread, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task. In this way, the security of thread context propagation and the efficiency of thread context propagation are improved, thereby improving the user experience.
[0057] Accordingly, see Figure 2 As shown, the present application also provides a thread execution device, including:
[0058] The decorator creation module 11 is used to create a target decorator corresponding to a preset thread pool based on user needs; the preset thread pool includes a plurality of task threads; the execution mode of the task thread is asynchronous execution;
[0059] A first decorator control module 12, used to control the target decorator to obtain a target context object corresponding to the current task thread in the preset thread pool by using a preset context acquisition method;
[0060] The second decorator control module 13 is used to control the target decorator to set the target context object in the target task thread using a preset setting method, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task; the target task thread is a task thread that has a sequence with the current task thread and has not been executed.
[0061] As can be seen from the above, before executing the thread, the embodiment of the present application needs to create a target decorator corresponding to the preset thread pool based on user needs; the preset thread pool includes several task threads; the execution mode of the task thread is asynchronous execution; the target decorator is controlled to obtain the target context object corresponding to the current task thread in the preset thread pool using the preset context acquisition method; the target decorator is controlled to set the target context object in the target task thread using the preset setting method, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task; the target task thread is a task thread that has a sequence with the current task thread and has not been executed. It can be seen that the present application obtains the target context object corresponding to the current task thread in the preset thread pool by controlling the target decorator, and sets the target context object in the target task thread, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task. In this way, the security of thread context propagation and the efficiency of thread context propagation are improved, thereby improving the user experience.
[0062] In some specific implementations, the decorator creation module 11 may specifically include:
[0063] A thread pool construction unit, used to construct the preset thread pool through a preset thread pool construction algorithm in a preset interface;
[0064] The decorator creation subunit is used to utilize the preset decorator setting method in the preset interface and create a target decorator corresponding to the preset thread pool based on user needs.
[0065] In some specific implementations, the thread execution device may further include:
[0066] The first task annotation unit is used to annotate the thread tasks corresponding to the plurality of task threads in the preset thread pool respectively by using a first preset annotation method, so as to support asynchronous calling of the plurality of thread tasks.
[0067] In some specific implementations, the thread execution device may further include:
[0068] The second task annotation unit is used to annotate the plurality of thread tasks using a second preset annotation method, so that the preset framework creates corresponding target task threads for the plurality of thread tasks respectively, and triggers the target task threads to asynchronously execute the operations of the corresponding thread tasks using the information in the target context object; wherein the execution time of the first preset annotation method is earlier than the execution time of the second preset annotation method.
[0069] In some specific implementations, the thread execution device may further include:
[0070] A space creation unit, used to create a preset context management space corresponding to the preset thread pool;
[0071] An object storage unit is used to store context objects corresponding to several of the task threads in the preset thread pool in the preset context management space, so that the target decorator obtains the target context object corresponding to the current task thread in the preset thread pool from the preset context management space.
[0072] In some specific implementations, the thread execution device may further include:
[0073] The object clearing unit is used to clear the target context object corresponding to the target task thread using a preset clearing method.
[0074] Furthermore, the present application also discloses an electronic device. Figure 3 1 is a structural diagram of an electronic device 20 according to an exemplary embodiment, and the content in the figure cannot be regarded as any limitation on the scope of use of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the thread execution method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0075] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0076] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0077] The operating system 221 is used to manage and control the hardware devices on the electronic device 20 and the computer program 222, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the thread execution method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.
[0078] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the thread execution method disclosed above is implemented. For the specific steps of the method, reference may be made to the corresponding contents disclosed in the above embodiments, and no further description will be given here.
[0079] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0080] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0081] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0082] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0083] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A thread execution method, characterized in that: include: A target decorator corresponding to a preset thread pool is created based on user needs; the preset thread pool includes a plurality of task threads; the task threads are executed asynchronously; Control the target decorator to obtain a target context object corresponding to the current task thread in the preset thread pool using a preset context acquisition method; Control the target decorator to set the target context object in the target task thread using a preset setting method, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task; the target task thread is a task thread that has a sequence with the current task thread and has not been executed.
2. The thread execution method according to claim 1, characterized in that: The method of creating a target decorator corresponding to a preset thread pool based on user requirements includes: Constructing the preset thread pool by using the preset thread pool construction algorithm in the preset interface; The preset decorator setting method in the preset interface is utilized, and a target decorator corresponding to the preset thread pool is created based on user requirements.
3. The thread execution method according to claim 1, characterized in that: After creating a target decorator corresponding to the preset thread pool based on user needs, it also includes: The thread tasks respectively corresponding to the several task threads in the preset thread pool are annotated using a first preset annotation method to support asynchronous calling of the several thread tasks.
4. The thread execution method according to claim 3, characterized in that: After controlling the target decorator to set the target context object in the target task thread using a preset setting method, the method further includes: Annotating the plurality of thread tasks using a second preset annotation method so that the preset framework creates corresponding target task threads for the plurality of thread tasks respectively, and triggers the target task threads to asynchronously execute operations of corresponding thread tasks using information in the target context object; The execution time of the first preset annotation method is earlier than the execution time of the second preset annotation method.
5. The thread execution method according to claim 1, characterized in that: Before controlling the target decorator to obtain the target context object corresponding to the current task thread in the preset thread pool using a preset context acquisition method, the method further includes: Creating a preset context management space corresponding to the preset thread pool; The context objects corresponding to the plurality of task threads in the preset thread pool are stored in the preset context management space, so that the target decorator obtains the target context object corresponding to the current task thread in the preset thread pool from the preset context management space.
6. The thread execution method according to claim 1, characterized in that: After the target decorator is controlled to set the target context object in the target task thread using a preset setting method so that the target task thread asynchronously executes the corresponding thread task using the information in the target context object, the method further includes: The target context object corresponding to the target task thread is cleared using a preset clearing method.
7. The thread execution method according to any one of claims 1 to 6, characterized in that: The target decorator is DemoContextDecorator, the preset context acquisition method is the ThreadLocal algorithm, the preset setting method is the getContext() algorithm of SecurityContextHolder, and the target context object is SecurityContext.
8. A thread execution device, characterized in that: include: A decorator creation module is used to create a target decorator corresponding to a preset thread pool based on user needs; the preset thread pool includes a number of task threads; the execution mode of the task thread is asynchronous execution; A first decorator control module, used to control the target decorator to obtain a target context object corresponding to the current task thread in the preset thread pool by using a preset context acquisition method; The second decorator control module is used to control the target decorator to set the target context object in the target task thread using a preset setting method, so that the target task thread uses the information in the target context object to asynchronously execute the corresponding thread task; the target task thread is a task thread that has a sequence with the current task thread and has not been executed.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the steps of the thread execution method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the steps of the thread execution method according to any one of claims 1 to 7 are implemented.