CN114610413A - Method, device, equipment and storage medium for executing synchronous and asynchronous tasks based on Java - Google Patents

Method, device, equipment and storage medium for executing synchronous and asynchronous tasks based on Java Download PDF

Info

Publication number
CN114610413A
CN114610413A CN202210283089.1A CN202210283089A CN114610413A CN 114610413 A CN114610413 A CN 114610413A CN 202210283089 A CN202210283089 A CN 202210283089A CN 114610413 A CN114610413 A CN 114610413A
Authority
CN
China
Prior art keywords
execution
flow
task
child node
java
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210283089.1A
Other languages
Chinese (zh)
Inventor
郑盛样
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Puhui Enterprise Management Co Ltd
Original Assignee
Ping An Puhui Enterprise Management Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN202210283089.1A priority Critical patent/CN114610413A/en
Publication of CN114610413A publication Critical patent/CN114610413A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention relates to the technical field of computers, and discloses a method, a device, equipment and a storage medium for executing synchronous and asynchronous tasks based on Java. The method comprises the following steps: when a task execution request sent by a user is received, calling an execution inlet of a Java secondary flow at the last execution stage of the execution of a Java main flow, and acquiring a task chain corresponding to the task from the execution inlet; acquiring a preset flow execution record table, a flow configuration table and a sub-node configuration table, respectively executing sub-nodes in the task chain according to the flow execution record table, the flow configuration table and the sub-node configuration table, and acquiring an execution result after the sub-nodes are executed; the task chain comprises a plurality of child nodes; and updating the execution state corresponding to the task in the flow execution record table according to the execution result. The invention executes the original complex synchronous and asynchronous task execution flow through the child nodes, thereby improving the flexibility of the system for executing tasks.

Description

Method, device, equipment and storage medium for executing synchronous and asynchronous tasks based on Java
Technical Field
The invention relates to the technical field of computers, and particularly discloses a method, a device, equipment and a storage medium for executing synchronous and asynchronous tasks based on Java.
Background
At present, in the process of executing a task, if an execution link with a complex flow is encountered, from a main flow to a secondary flow, the Java application system generally adopts the following three schemes:
the first scheme is that an execution mode that a task is executed once from top to bottom from a main process to a secondary process is adopted; the disadvantages of the scheme are that: the system code coupling degree is high, the secondary process is highly coupled with the main process, the main process is influenced by the failure of the secondary process, and the system maintenance cost is increased along with the increase of the process complexity; the first mode also affects the response efficiency of the real-time interface scene, and the main process needs to wait for the completion of the execution of the secondary process to perform response, thereby spending more time.
The second scheme is to introduce a workflow component of a third party and to linearly line the housekeeping in the process through the workflow component of the third party; the disadvantages of the scheme are that: the system is easily cumbersome and the additional dependencies and configurations of typical workflow components to accommodate different scenarios and greater flexibility are quite large, and thus the use of such workflow components may introduce some unnecessary dependencies and configurations.
The third scheme is that in the main flow, the task in the flow is executed in an asynchronous thread mode; the disadvantages of the scheme are that: the management requirement for the asynchronous thread is high, so how to deal with the problems of execution failure, loss and the like of the asynchronous thread needs to be considered.
In view of the above, there is a need for a new solution to solve the above problems.
Disclosure of Invention
Therefore, it is necessary to provide a method, an apparatus, a device and a storage medium for executing Java-based synchronous and asynchronous tasks, where the original complex synchronous and asynchronous task execution process is executed through a child node, so as to improve the flexibility of the system in executing tasks.
A method for executing Java-based synchronous and asynchronous tasks comprises the following steps:
when a task execution request sent by a user is received, calling an execution inlet of a Java secondary flow at the last execution stage of the execution of a Java main flow, and acquiring a task chain corresponding to the task from the execution inlet;
acquiring a preset flow execution record table, a flow configuration table and a sub-node configuration table, respectively executing sub-nodes in the task chain according to the flow execution record table, the flow configuration table and the sub-node configuration table, and acquiring an execution result after the sub-nodes are executed; the task chain comprises a plurality of child nodes;
and updating the execution state corresponding to the task in the flow execution record table according to the execution result.
A Java-based execution device for synchronous and asynchronous tasks, comprising:
the acquisition module is used for calling an execution inlet of a Java secondary flow at the last execution stage of the execution of a Java main flow when a task execution request sent by a user is received, and acquiring a task chain corresponding to the task from the execution inlet;
the execution module is used for acquiring a preset flow execution record table, a flow configuration table and a sub-node configuration table, respectively executing the sub-nodes in the task chain according to the flow execution record table, the flow configuration table and the sub-node configuration table, and acquiring an execution result after the sub-nodes are executed; the task chain comprises a plurality of child nodes;
and the updating module is used for updating the execution state corresponding to the task in the flow execution record table according to the execution result.
A computer device comprising a memory, a processor and a computer program stored in said memory and executable on said processor, said processor implementing a method of execution of a Java based asynchronous and asynchronous task as described above when executing said computer program.
A computer-readable storage medium, in which a computer program is stored, which, when executed by a processor, implements a method of performing a Java-based co-asynchronous task as described above.
According to the method, the device, the equipment and the storage medium for executing the Java-based synchronous and asynchronous tasks, the Java main flow and the Java sub-flow corresponding to the tasks are stripped, so that the complexity of the main flow logic can be effectively reduced (namely, the maintenance cost of the system can be saved), the processing efficiency of the main flow can be effectively improved (namely, the response efficiency of the main flow is improved), and further, the pressure of the system in the main flow stage can be reduced; complex flow nodes in the original task are nodulated, namely Java secondary flows are replaced by sub-nodes, the sub-nodes can be multiplexed by a flow configuration table and a flow execution record table, and the sub-node execution sequence of the sub-nodes can be adjusted by the sub-node configuration table, so that the code coupling degree of a system code can be effectively reduced, and the flexibility of the system can be improved; and a third-party workflow framework is not required to be introduced, so that the system cannot become bloated, and meanwhile, the problem of loopholes from the third-party workflow framework is also solved because the third-party workflow framework is not required to be relied on.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments of the present invention will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive labor.
FIG. 1 is a schematic diagram of an application environment of a method for executing Java-based synchronous and asynchronous tasks according to an embodiment of the present invention;
FIG. 2 is a flow chart illustrating a method for executing Java-based synchronous and asynchronous tasks according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of an apparatus for executing Java-based asynchronous and synchronous tasks according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a computer device according to an embodiment of the invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The execution method of the Java-based synchronous and asynchronous task can be applied to the application environment shown in figure 1, wherein a client communicates with a server through a network. The client may include, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices, among others.
In an embodiment, as shown in fig. 2, a method for executing Java-based synchronous and asynchronous tasks is provided, which is illustrated by taking the method as an example of the server in fig. 1 (the system mentioned in the present invention runs on the server), and includes the following steps S101-S301:
s101, when a task execution request sent by a user is received, calling an execution inlet of a Java secondary flow at the last execution stage of the execution of a Java main flow, and acquiring a task chain corresponding to the task from the execution inlet;
understandably, the tasks comprise asynchronous tasks and synchronous tasks, when the tasks are asynchronous tasks, the synchronous execution entries of the Java secondary flows are called asynchronously, and when the tasks are synchronous tasks, the asynchronous execution entries of the Java secondary flows are called synchronously; the final execution stage of the main flow of the Java is a stage in which complex business logic needs to be triggered, namely a stage in which a task chain needs to be triggered; the Java main flow refers to code logic before triggering a task chain, the Java secondary flow refers to a task chain, the task chain refers to a function with complex business logic in a system, and includes a plurality of child nodes, for example, for a user applies for a task of revoking a mortgage, where the related Java main flow and Java secondary flow are: 1. accepting a revocation application; 2. the mail informs the service staff of processing the application; 3. generating an electronic document for canceling the mortgage; 4. stamping the electronic document with a seal; the step 1 of responding to the user in real time, the step 2, the step 3 and the step 4 of responding to the user in real time are not needed, at the moment, the step 1 can be understood as a Java main flow, the step 2, the step 3 and the step 4 can be understood as Java secondary flows, the step 2, the step 3 and the step 4 can be packaged into an asynchronous task chain, in addition, when the step 1 is finished, the task chain packaged by the step 2, the step 3 and the step 4 is asynchronously generated, then the user can be responded immediately, and the user is informed of successful acceptance on an interface; then the system processes the logics of 2, 3 and 4 according to the sequence of the task chain in an asynchronous calling mode;
in this embodiment, the Java main flow and the Java sub flow corresponding to the task are stripped, which not only can effectively reduce the complexity of the main flow logic (i.e., save the maintenance cost of the system), but also can effectively improve the processing efficiency of the main flow (i.e., improve the response efficiency of the main flow), and further can reduce the pressure of the system in the main flow stage.
S201, acquiring a preset flow execution record table, a flow configuration table and a sub-node configuration table, respectively executing sub-nodes in the task chain according to the flow execution record table, the flow configuration table and the sub-node configuration table, and acquiring an execution result after the sub-nodes are executed; the task chain comprises a plurality of child nodes;
understandably, the flow execution table is used as the basic configuration of a task chain, and comprises a definition of the task chain and each included child node (the child node can be understood as a child task or a child process), and the use scene of the flow execution table is that when the task chain is triggered, the system reads the child node configuration information of the child node configuration table corresponding to the task chain, and executes each child node according to the child node configuration information; the flow configuration table is an execution record of the task chain, is used for recording the execution condition of the task chain, and can also be used for checking the execution result of the task chain, if the execution result is execution failure, the reason of the execution failure can be positioned through a child node of the execution failure and error information, and the use scene of the flow configuration table is that after a single task is generated, when the task execution is finished, the condition corresponding to the execution result of the task is recorded; the method comprises the steps that a child node configuration table is used for configuring nodes and comprises definition of a single child node and an execution sequence of the child node on a task chain, and a use scene of the child node configuration table is that when the task chain is triggered, a system reads child node configuration information of the task chain and executes each child node according to the child node configuration information; the specific three tables may be (for each attribute in the chart):
Figure BDA0003558791960000061
Figure BDA0003558791960000062
Figure BDA0003558791960000071
Figure BDA0003558791960000072
in addition, before the child node tasks in the task Chain are executed according to the flow execution record table, the flow configuration table and the child node configuration table, a task Chain abstract class abstract Chain needs to be defined, and a task Chain interface Chain (including an asynchronous execution entry or a defined synchronous execution entry) needs to be inherited;
specifically, firstly, the asynchronous function processDelay is realized through a flow execution record table, namely, the executed ginseng is written into the flow execution record table according to the system concurrency, and meanwhile, the state of the asynchronous task or the synchronous task is recorded as to-be-processed; then, the synchronous function process is realized through the flow configuration table and the child node configuration table, namely, a child node list containing child nodes is obtained through the flow configuration table, after the child node configuration table is inquired, a child node execution sequence is obtained, child nodes in the child node list are sequenced according to the child node execution sequence, and a child node list to be executed is obtained; then, after traversing the child node column to be executed, obtaining the bean of the child node, and calling the child node corresponding to the bean of the child node to execute an entry process in a dynamic proxy manner (the process includes a process of judging whether each child node with child node execution sequence in the word node list is continuously executed or not); finally, the sub-node execution entry process obtains the returned execution result after the sub-node is executed, wherein the execution result comprises success and failure results;
in the embodiment, a mode that a task chain includes child nodes is adopted, the complex flow nodes in the original task are changed into Java secondary flows, the child nodes can be multiplexed through a flow configuration table and a flow execution record table, and the child node execution sequence of the child nodes can be adjusted through the child node configuration table, so that the system code coupling degree can be effectively reduced, and the system flexibility can be improved.
And S301, updating the execution state corresponding to the task in the flow execution record table according to the execution result.
It should be understood that, in all the child nodes having the child node execution sequence in the child node list, if the execution result corresponding to one child node is failure, the execution state corresponding to the task in the flow execution record table is a failed execution state, and if the execution result corresponding to all the child nodes is success, the execution state corresponding to the task in the flow execution record table is a successful execution state.
In the embodiments from step S101 to step S301, the Java main flow and the Java sub flow corresponding to the task are stripped, which not only can effectively reduce the complexity of the main flow logic (i.e., can save the maintenance cost of the system), but also can effectively improve the processing efficiency of the main flow (i.e., improve the response efficiency of the main flow), thereby reducing the pressure of the system in the main flow stage; complex flow nodes in the original task are nodulated, namely Java secondary flows are replaced by sub-nodes, the sub-nodes can be multiplexed by a flow configuration table and a flow execution record table, and the sub-node execution sequence of the sub-nodes can be adjusted by the sub-node configuration table, so that the code coupling degree of a system code can be effectively reduced, and the flexibility of the system can be improved; and a third-party workflow framework is not required to be introduced, so that the system cannot become bloated, and meanwhile, the problem of loopholes from the third-party workflow framework is also solved because the third-party workflow framework is not required to be relied on.
Further, before the step S201, the method further includes:
and setting attributes and attribute values required by the task chain, and establishing a flow execution record table, a flow configuration table and a child node configuration table according to the attributes and the attribute values.
Understandably, the attributes in the 3 tables mentioned above are process codes (attribute values may be process 1 and process 2), process names (attribute values may be stamp for notifying the operator of the mail processing application, generating the electronic document for canceling the mortgage and electronic document), and sub-process code lists (attribute values may be list formed by process 1 and process 2 for providing the sub-node list corresponding to the task chain, one sub-process corresponding to one sub-node), node codes (attribute values are nodeA, nodeB and nodeC), node names and node sequences (attribute values are nodeA- > nodeB- > nodeC, for providing the execution sequence of the sub-nodes), node codes (attribute values are nodeA, nodeB and nodeC), business keywords (same task keywords as in asynchronous tasks), and the like, Service messages (specific task contents of asynchronous and asynchronous tasks), a failed node list (list formed by failed execution of child nodes), processing times (for reflecting the times of repeated execution), processing results (for reflecting execution states) and error information (for reflecting failure reasons, such as execution failure caused by data problems or logic problems of child nodes in a task chain).
Further, after the setting of the attributes and attribute values required by the task chain, the method further includes:
and acquiring a process code and a node code in the attribute, and defining the process code and the node code as the BeanName of the Java class of the task chain in an application container.
Understandably, the beans in the Bean name are the label attribute of the Spring application container, the Bean name represents that each Bean object in the Spring application container has a unique name, and further configuration information (attributes corresponding to the child nodes, such as flow codes and node codes) can be extracted through the unique name; after the setting of the attributes and attribute values in the three tables is completed, in order to obtain the child node beans from the application container through the bean name in the subsequent process, and finally, call the execution entry process of the child node corresponding to the child node beans in a dynamic proxy manner, it is necessary to define the flow code and the node code in the attributes to be consistent with the bean name of the Java class of the task chain in the application container, and include defining the flow code (task chain code) to be consistent with the bean name of the Java class of the task chain in the application container, if a task chain class demoProcess is defined in the Java code, the flow code (task chain code) is demoProcess, and also include defining the node code to be consistent with the bean name of the Java class of the task chain node in the application container, if a node class demonode.
Further, the execution entries include an asynchronous execution entry and a synchronous execution entry; before the calling the execution entry of the Java secondary flow at the last execution stage of the execution of the Java main flow, the method further comprises the following steps:
an asynchronous execution entry is defined or a synchronous execution entry is defined.
Understandably, the embodiment is a process for defining a task Chain, Chain; the definition can be specifically made by the following Java code:
defining an asynchronous execution entry: void processDelay (T param);
b. defining a synchronous execution entry: void process (T param).
Further, before the executing the child node tasks in the task chain according to the flow execution record table, the flow configuration table, and the child node configuration table, the method further includes:
when the concurrency of the system is determined to be less than or equal to the preset threshold value, writing the execution entry parameters in the task chain corresponding to the tasks into the flow execution record table, and recording the execution states of the tasks corresponding to the execution entry parameters in the flow execution record table as to-be-processed;
when the concurrency of the system is larger than the preset threshold value, writing execution entries in a task chain corresponding to the tasks into a waiting queue, writing the execution entries into the flow execution record table in batches through the waiting queue, and recording the execution states of the tasks corresponding to the execution entries in the flow execution record table as to-be-processed.
Understandably. The execution entry may be understood as entering an object (e.g., a request ID-request ID of a user, an operation object-operator of the user), where the object is used to determine that an execution state corresponding to a task in a system execution process (i.e., a concurrency amount of a task executed by the system) is to be processed; according to the embodiment, different implementation modes are selected according to the concurrency condition of the system, and the operation efficiency of the system is further improved.
Further, after writing the execution join in the task chain corresponding to the task into the flow execution record table or after writing the execution join in batch into the flow execution record table through the wait queue, the method further includes:
acquiring the BeanName through the execution access;
after inquiring the attribute in the flow configuration table through the BeanName, obtaining a child node list containing a plurality of child nodes;
after inquiring the child node configuration table, obtaining a child node execution sequence;
and sequencing all the child nodes in the child node list according to the child node execution sequence to obtain a child node list to be executed.
Understandably, after the execution entry is written into the process execution record table, firstly, the class name of a caller is obtained in the process execution record table in a way of this.
Further, after obtaining the child node list to be executed, the method further includes:
after traversing the child node list to be executed, acquiring node codes corresponding to the nodes of the child node list to be executed from the flow execution record table or the child node configuration table, and calling an acquisition function in an application container through the node codes to acquire the bean of the child node with the most front child node execution sequence;
calling an execution inlet of a child node corresponding to a bean of the child node at the top of the execution sequence of the child node in a dynamic proxy mode, and simultaneously obtaining an execution result after the child node is executed, wherein the execution result is returned from the execution inlet of the child node;
determining whether a next-later child node of a child node which is earlier in the execution sequence of the child node needs to be executed according to the execution result;
when the execution result is determined to be successful, continuously acquiring the bean of the next child node, calling the execution entry of the child node corresponding to the bean of the next child node in a dynamic proxy mode, acquiring the execution result after the child node is executed, returned from the execution entry of the child node, and determining whether the next node of the next child node needs to be executed again according to the execution result;
and when the execution result is determined to be a failure, acquiring a failure child node and a failure reason corresponding to the failure execution result.
Understandably, dynamic proxy is a technique for creating a proxy object of a target object and performing functional enhancement on a method in the target object during program operation; bean is the label attribute of the Spring application container; the obtaining function is getBean (), the obtaining function in the application container is called through node coding to obtain the bean of the child node with the top execution sequence of the child node, and the bean corresponding to the child node is obtained through calling getBean () of the applicationContext; the execution result returned by the execution entry of the child node can be reflected by the boolean value (each child node needs to return a boolean value), true represents that all the child nodes in the task chain are executed completely, false represents that the node is executed completely, and the next node can be executed continuously.
In another embodiment, after the obtaining of the failure child node and the failure reason corresponding to the failed execution result when the execution result is determined to be a failure, the method further includes;
according to the execution result of the flow execution record table, skipping the executed child nodes with the execution results being successful, and repeatedly executing the child nodes with the execution failures; the repeated execution operation comprises calling an execution inlet of the child node corresponding to the bean of the child node with failed execution in a dynamic proxy mode, and acquiring an execution result after the child node is executed, wherein the execution result is returned from the execution inlet of the child node; the embodiment is to make compatible a scenario in which a sub-node execution result in a task chain is a failure, for example, a task chain demoProcess includes three sub-nodes: and the execution sequence of nodeA, nodeB and nodeC is A- > B- > C, so that in the execution process, the execution state of the task chain can be a failed execution state due to a data problem or a logic problem in nodeB, and the nodeB can be repeatedly executed.
Further, before the invoking of the node execution entry corresponding to the bean of the child node at the top of the child node execution order by the dynamic proxy, the method further includes:
a node execution entry is defined.
Understandably, the embodiment is a process for defining a Node interface Node; the definition can be specifically made by the following Java code:
defining a node execution entry, true representing the flow termination of the task chain, false representing the permission of continuing to execute the next node:
boolean process(T param)。
further, the updating the execution state corresponding to the task in the flow execution record table according to the execution result includes:
when the execution results corresponding to all the child nodes are determined to be successful, updating the execution state in the flow execution record table corresponding to the task to be a successful execution state;
when the execution result corresponding to one of the child nodes is determined to be failure, updating the execution state in the flow execution record table corresponding to the task to be a failure execution state, and updating the failure child node and the failure reason to the flow execution record table; and the successful execution state and the failed execution state are used as attribute values of the execution result in the flow execution record table.
Understandably, the failed child node is a child node which fails to execute; the failure reason can be that the child nodes in a task chain fail to execute due to data problems or logic problems, for example, nodeA- > nodeB- > nodeC in a task chain, and nodeB fails to execute; in this embodiment, the states of the abnormal child node and the normally executed child node are updated, and the execution states in the flow execution record table are mainly inverted (including being inverted into a successful execution state and a failed execution state); in this embodiment, when it is determined that an execution result corresponding to one of the child nodes is a failure, an execution state in a flow execution record table corresponding to the task is updated to a failure execution state, and before the failure child node and a failure reason are updated to the flow execution record table, an execution failure needs to be captured (i.e., exception capture).
Further, when it is determined that the execution result corresponding to one of the child nodes is a failure, updating the execution state in the flow execution record table corresponding to the task to a failure execution state, and updating the failure child node and the failure reason to the flow execution record table, the method further includes:
polling the flow execution record table according to preset time, inquiring the data of which the execution state is the failed execution state from the flow execution record table, and transmitting the data of which the execution state is the failed execution state into a synchronous execution inlet in the execution inlets so as to execute the task chain corresponding to the data of which the execution state is the failed execution state again.
Understandably, in the present embodiment, a complementary processing mechanism for implementing an execution failure through a synchronous execution entry is used, and data of a task chain corresponding to an execution state being a failed execution state is again transferred into the execution entry to implement re-execution (re-execution may be a child node in the task chain whose execution failed), and the problem that the existing asynchronous thread processing has a high management requirement when the execution failure is processed is solved through the present embodiment.
Further, the method further comprises:
the new child node and the child node execution sequence of the new child node are configured to the flow configuration table;
and newly building a flow, and configuring the newly built flow and a child node list required by the newly built flow to the flow configuration table.
Understandably, a Node (child Node) interface and a process (child Node execution entry) method thereof are realized by newly building child nodes, and then child Node logics are compiled according to actual requirements, meanwhile, different values can be returned according to different scenes, whether the process continues to execute the next child Node or not is determined, and child Node information and an execution sequence are configured to a child Node configuration table; inheriting AbstractChain through a newly-built process class, further realizing no need of compiling logic, and configuring process information and a child node list required by the process to a process configuration table;
when the user requirement is changed, the new process only needs to be added or deleted (the new process is nodulated, and the new process also has a consistent effect), so that the system code reuse rate is improved, the maintenance cost of a developer can be reduced, and the workload of a tester is reduced.
In summary, the method for executing the Java-based synchronous and asynchronous task provided above strips the Java main flow and the Java sub flow corresponding to the task, which not only can effectively reduce the complexity of the main flow logic (i.e. save the maintenance cost of the system), but also can effectively improve the processing efficiency of the main flow (i.e. improve the response efficiency of the main flow), thereby reducing the pressure of the system in the main flow stage; complex flow nodes in the original task are nodulated, namely Java secondary flows are replaced by sub-nodes, the sub-nodes can be multiplexed by a flow configuration table and a flow execution record table, and the sub-node execution sequence of the sub-nodes can be adjusted by the sub-node configuration table, so that the code coupling degree of a system code can be effectively reduced, and the flexibility of the system can be improved; a third-party workflow framework is not required to be introduced, so that the system is not overstaffed, and meanwhile, the problem of loopholes from the third-party workflow framework is reduced as the third-party workflow framework is not required to be relied on; in addition, different implementation modes are selected according to the concurrency condition of the system, so that the operation efficiency of the system is improved; a complementary processing mechanism of execution failure is realized through a synchronous execution inlet, and the data of the task chain corresponding to the execution state of the failure execution state is transmitted to the execution inlet again to realize the re-execution, so that the problem of high management requirement when the execution failure is processed by adopting an asynchronous thread in the prior art is solved; in addition, when the user needs to be changed, only the child nodes need to be newly added or deleted, so that the system code reuse rate is improved, the maintenance cost of a developer can be reduced, and the workload of a tester is reduced.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
In an embodiment, the present invention further provides a Java-based synchronous and asynchronous task execution device, where the Java-based synchronous and asynchronous task execution device corresponds to the Java-based synchronous and asynchronous task execution method in the foregoing embodiment one to one. As shown in fig. 3, the apparatus for executing Java-based asynchronous and synchronous tasks includes an obtaining module 11, an executing module 12, and an updating module 13. The detailed description of each functional module is as follows:
the obtaining module 11 is configured to, when receiving a task execution request sent by a user, call an execution entry of a Java secondary flow at a last execution stage of execution of a Java main flow, and obtain a task chain corresponding to the task from the execution entry.
The execution module 12 is configured to acquire a preset flow execution record table, a flow configuration table, and a child node configuration table, execute a child node in the task chain according to the flow execution record table, the flow configuration table, and the child node configuration table, and acquire an execution result after the child node is executed; the task chain comprises a plurality of child nodes.
And the updating module 13 is configured to update the execution state corresponding to the task in the flow execution record table according to the execution result.
Further, the apparatus for executing the Java-based asynchronous and synchronous task further includes:
and the setting module is used for setting the attributes and attribute values required by the task chain and establishing the flow execution record table, the flow configuration table and the child node configuration table according to the attributes and the attribute values.
Further, the execution device of the Java-based synchronous and asynchronous task further comprises:
and the definition module is used for acquiring the process codes and the node codes in the attributes and defining the process codes and the node codes as the BeanName of the Java classes of the task chain in the application container.
Further, the apparatus for executing the Java-based asynchronous and synchronous task further includes:
the first recording module is used for writing the execution entry parameters in the task chain corresponding to the tasks into the flow execution recording table when the concurrency of the system is determined to be less than or equal to the preset threshold value, and recording the execution states of the tasks corresponding to the execution entry parameters in the flow execution recording table as to-be-processed;
and the second recording module is used for writing the execution parameters in the task chain corresponding to the tasks into a waiting queue when the system concurrency is determined to be greater than the preset threshold value, writing the execution parameters into the flow execution recording table in batches through the waiting queue, and recording the execution state of the tasks corresponding to the execution parameters in the flow execution recording table as to-be-processed.
Further, the first recording module or the second recording module further includes:
the execution parameter acquiring module is used for acquiring the BeanName through the execution parameter;
the first query module is used for obtaining a child node list containing a plurality of child nodes after querying the attributes in the process configuration table through the BeanName;
the second query module is used for obtaining the execution sequence of the child nodes after querying the child node configuration table;
and the sequencing module is used for sequencing all the child nodes in the child node list according to the child node execution sequence to obtain a child node list to be executed.
Further, the sorting module further comprises:
the traversal module is used for acquiring node codes corresponding to the nodes of the child node list to be executed from the flow execution record table or the child node configuration table after traversing the child node list to be executed, and acquiring the bean of the child node with the most front child node execution sequence by calling an acquisition function in the application container through the node codes;
the calling module is used for calling the execution inlet of the child node corresponding to the bean of the child node with the earliest execution sequence of the child nodes in a dynamic proxy mode and acquiring the execution result of the child node after execution, which is returned from the execution inlet of the child node;
a first determining module, configured to determine, according to the execution result, whether it is necessary to execute a next subsequent child node of a child node that is earlier in an execution order of the child node;
a second determining module, configured to, when it is determined that the execution result is successful, continue to obtain a bean of a next child node, call, in a dynamic proxy manner, an execution entry of the child node corresponding to the bean of the next child node, obtain an execution result after execution of the child node returned from the execution entry of the child node, and determine again whether it is determined, by using the execution result, that the next node of the next child node needs to be executed;
and the third determining module is used for acquiring a failure child node and a failure reason corresponding to the failure execution result when the execution result is determined to be failure.
Further, the execution module includes:
the first updating submodule is used for updating the execution state in the flow execution record table corresponding to the task to a successful execution state when the execution results corresponding to all the child nodes are determined to be successful;
a second updating sub-module, configured to update an execution state in a flow execution record table corresponding to the task to a failed execution state when it is determined that an execution result corresponding to one of the sub-nodes is a failure, and update the failed sub-node and a failure reason to the flow execution record table; the successful execution state and the failed execution state are used as attribute values of the execution result in the flow execution record table.
For specific limitations of the apparatus for executing Java-based asynchronous and synchronous tasks, refer to the above limitations of the method for executing Java-based asynchronous and synchronous tasks, which are not described herein again. The various modules in a Java-based execution device for synchronous and asynchronous tasks may be implemented in whole or in part by software, hardware, and combinations thereof. The modules can be embedded in a hardware form or independent of a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a server, the internal structure of which may be as shown in fig. 4. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The database of the computer device is used for storing data involved in the execution method of a Java-based synchronous and asynchronous task. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a method of executing Java-based synchronous and asynchronous tasks.
In one embodiment, a computer device is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the processor implements the steps of the method for executing the Java-based asynchronous and asynchronous tasks in the above embodiments, such as steps S101 to S301 shown in fig. 2. Alternatively, the processor, when executing the computer program, implements the functions of the modules/units of the Java-based asynchronous and asynchronous task execution device in the above embodiments, such as the functions of the modules 11 to 13 shown in fig. 3. To avoid repetition, further description is omitted here.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which when executed by a processor implements the steps of a method for executing a Java-based asynchronous and synchronous task in the above-described embodiments, such as steps S101 to S301 shown in fig. 2. Alternatively, the computer program, when executed by the processor, implements the functions of the modules/units of the execution apparatus of a Java-based asynchronous task in the above-described embodiments, such as the functions of the modules 11 to 13 shown in fig. 3. To avoid repetition, further description is omitted here.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, databases, or other media used in embodiments provided herein may include non-volatile and/or volatile memory. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein.

Claims (10)

1. A method for executing Java-based synchronous and asynchronous tasks, the method comprising:
when a task execution request sent by a user is received, calling an execution inlet of a Java secondary flow at the last execution stage of the execution of a Java main flow, and acquiring a task chain corresponding to the task from the execution inlet;
acquiring a preset flow execution record table, a flow configuration table and a sub-node configuration table, respectively executing sub-nodes in the task chain according to the flow execution record table, the flow configuration table and the sub-node configuration table, and acquiring an execution result after the sub-nodes are executed; the task chain comprises a plurality of child nodes;
and updating the execution state corresponding to the task in the flow execution record table according to the execution result.
2. The method for executing Java-based asynchronous and synchronous tasks according to claim 1, wherein before acquiring the preset flow execution record table, the preset flow configuration table, and the preset child node configuration table, respectively executing the child nodes in the task chain according to the flow execution record table, the preset flow configuration table, and the preset child node configuration table, and acquiring the execution result after executing the child nodes, the method further comprises:
and setting attributes and attribute values required by the task chain, and establishing a flow execution record table, a flow configuration table and a child node configuration table according to the attributes and the attribute values.
3. The method for executing a Java-based synchronous and asynchronous task according to claim 2, wherein after the setting of the attributes and attribute values required by the task chain, the method further comprises:
and acquiring a process code and a node code in the attribute, and defining the process code and the node code as the BeanName of the Java class of the task chain in an application container.
4. The method according to claim 1, wherein before the executing the child nodes in the task chain according to the flow execution record table, the flow configuration table, and the child node configuration table, the method further comprises:
when the concurrency of the system is determined to be less than or equal to the preset threshold value, writing the execution entry parameters in the task chain corresponding to the tasks into the flow execution record table, and recording the execution states of the tasks corresponding to the execution entry parameters in the flow execution record table as to-be-processed;
when the concurrency of the system is determined to be greater than the preset threshold value, writing the execution access parameters in the task chain corresponding to the tasks into a waiting queue, writing the execution access parameters into the flow execution record table in batches through the waiting queue, and recording the execution state of the tasks corresponding to the execution access parameters in the flow execution record table as to-be-processed.
5. The method according to claim 4, wherein after writing the execution entries in the task chain corresponding to the task into the flow execution log table or after writing the execution entries in the batch into the flow execution log table through the wait queue, the method further comprises:
acquiring the BeanName through the execution access;
after inquiring the attribute in the process configuration table through the BeanName, obtaining a child node list containing a plurality of child nodes;
after inquiring the child node configuration table, obtaining a child node execution sequence;
and sequencing all the child nodes in the child node list according to the child node execution sequence to obtain a child node list to be executed.
6. The method for executing Java-based synchronous and asynchronous task according to claim 5, further comprising, after obtaining the list of child nodes to be executed:
after traversing the child node list to be executed, acquiring node codes corresponding to the nodes of the child node list to be executed from the flow execution record table or the child node configuration table, and acquiring the bean of the child node with the most front child node execution sequence by calling an acquisition function in an application container through the node codes;
calling an execution inlet of a child node corresponding to a bean of the child node at the top of the execution sequence of the child node in a dynamic proxy mode, and simultaneously obtaining an execution result after the child node is executed, wherein the execution result is returned from the execution inlet of the child node;
determining whether a next-later child node of a child node which is earlier in the execution sequence of the child node needs to be executed according to the execution result;
when the execution result is determined to be successful, continuously acquiring the bean of the next child node, calling the execution entry of the child node corresponding to the bean of the next child node in a dynamic proxy mode, acquiring the execution result after the child node is executed, returned from the execution entry of the child node, and determining whether the next node of the next child node needs to be executed again according to the execution result;
and when the execution result is determined to be failure, acquiring a failure child node and a failure reason corresponding to the failure execution result.
7. The method for executing the Java-based synchronous and asynchronous task according to claim 1, wherein the updating the execution state corresponding to the task in the flow execution log according to the execution result includes:
when the execution results corresponding to all the child nodes are determined to be successful, updating the execution state in the flow execution record table corresponding to the task into a successful execution state;
when the execution result corresponding to one of the child nodes is determined to be failure, updating the execution state in the flow execution record table corresponding to the task to be a failure execution state, and updating the failure child node and the failure reason to the flow execution record table; the successful execution state and the failed execution state are used as attribute values of the execution result in the flow execution record table.
8. An apparatus for executing a Java-based synchronous and asynchronous task, the apparatus comprising:
the acquisition module is used for calling an execution inlet of a Java secondary flow at the last execution stage of the execution of a Java main flow when a task execution request sent by a user is received, and acquiring a task chain corresponding to the task from the execution inlet;
the execution module is used for acquiring a preset flow execution record table, a flow configuration table and a sub-node configuration table, respectively executing the sub-nodes in the task chain according to the flow execution record table, the flow configuration table and the sub-node configuration table, and acquiring an execution result after the sub-nodes are executed; the task chain comprises a plurality of child nodes;
and the updating module is used for updating the execution state corresponding to the task in the flow execution record table according to the execution result.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements a method for performing a Java based asynchronous and synchronous task according to any of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored, which, when being executed by a processor, carries out a method for performing a Java based asynchronous and synchronous task as claimed in any one of claims 1 to 7.
CN202210283089.1A 2022-03-22 2022-03-22 Method, device, equipment and storage medium for executing synchronous and asynchronous tasks based on Java Pending CN114610413A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210283089.1A CN114610413A (en) 2022-03-22 2022-03-22 Method, device, equipment and storage medium for executing synchronous and asynchronous tasks based on Java

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210283089.1A CN114610413A (en) 2022-03-22 2022-03-22 Method, device, equipment and storage medium for executing synchronous and asynchronous tasks based on Java

Publications (1)

Publication Number Publication Date
CN114610413A true CN114610413A (en) 2022-06-10

Family

ID=81865382

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210283089.1A Pending CN114610413A (en) 2022-03-22 2022-03-22 Method, device, equipment and storage medium for executing synchronous and asynchronous tasks based on Java

Country Status (1)

Country Link
CN (1) CN114610413A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116521400A (en) * 2023-07-04 2023-08-01 京东科技信息技术有限公司 Article information processing method and device, storage medium and electronic equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130167126A1 (en) * 2009-10-15 2013-06-27 Adobe Systems Incorporated In-order execution in an asynchronous programming environment
CN110599119A (en) * 2019-08-27 2019-12-20 南凌科技股份有限公司 Business-oriented customizable workflow engine algorithm
CN111738591A (en) * 2020-06-19 2020-10-02 苏州浪潮智能科技有限公司 Task execution method, device and equipment and readable storage medium
US20210382731A1 (en) * 2020-06-07 2021-12-09 Asaf Ben Natan Method for componentization of enterprise applications using plugins

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130167126A1 (en) * 2009-10-15 2013-06-27 Adobe Systems Incorporated In-order execution in an asynchronous programming environment
CN110599119A (en) * 2019-08-27 2019-12-20 南凌科技股份有限公司 Business-oriented customizable workflow engine algorithm
US20210382731A1 (en) * 2020-06-07 2021-12-09 Asaf Ben Natan Method for componentization of enterprise applications using plugins
CN111738591A (en) * 2020-06-19 2020-10-02 苏州浪潮智能科技有限公司 Task execution method, device and equipment and readable storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
张利君 等: "基于工作流的动态任务调度研究与实现", 计算机工程与设计, no. 10, pages 2533 - 2537 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116521400A (en) * 2023-07-04 2023-08-01 京东科技信息技术有限公司 Article information processing method and device, storage medium and electronic equipment
CN116521400B (en) * 2023-07-04 2023-11-03 京东科技信息技术有限公司 Article information processing method and device, storage medium and electronic equipment

Similar Documents

Publication Publication Date Title
CN110069572B (en) HIVE task scheduling method, device, equipment and storage medium based on big data platform
US5528503A (en) Integrated automation development system and method
CN112738060B (en) Method and device for processing micro-service data, micro-service processing platform and medium
CN107241315B (en) Access method and device of bank gateway interface and computer readable storage medium
CN113220431B (en) Cross-cloud distributed data task scheduling method, device and storage medium
CN111026602A (en) Health inspection scheduling management method and device of cloud platform and electronic equipment
CN109389299B (en) Workflow process deployment method, workflow process deployment device, computer equipment and storage medium
CN112631686A (en) Data processing method, data processing device, computer equipment and storage medium
CN113094125B (en) Business process processing method, device, server and storage medium
CN110764894A (en) Timed task management method, device, equipment and storage medium
CN116016531A (en) Batch shutdown processing method and device
CN114610413A (en) Method, device, equipment and storage medium for executing synchronous and asynchronous tasks based on Java
CN113946427A (en) Task processing method, processor and storage medium for multi-operating system
CN112506590A (en) Interface calling method and device and electronic equipment
CN112395339A (en) Method and device for checking data access between systems, computer equipment and storage medium
CN114090268B (en) Container management method and container management system
CN110489208B (en) Virtual machine configuration parameter checking method, system, computer equipment and storage medium
CN110716972A (en) Method and device for processing error of high-frequency calling external interface
CN113031960B (en) Code compiling method, device, server and storage medium
CN116360752B (en) Function programming method oriented to java, intelligent terminal and storage medium
CN117573396B (en) Distributed workflow event processing method, device and medium
CN114978903B (en) Configuration issuing method, device, server and readable storage medium
CN113687882B (en) Activiti-based flow rollback method, activiti-based flow rollback device and storage medium
US20220358003A1 (en) Data Management Method, Apparatus, and Device, Computer-Readable Storage Medium, and System
CN117370197A (en) Test continuous operation method, device, terminal equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
AD01 Patent right deemed abandoned
AD01 Patent right deemed abandoned

Effective date of abandoning: 20240712