CN113051055A - Task processing method and device - Google Patents

Task processing method and device Download PDF

Info

Publication number
CN113051055A
CN113051055A CN202110315805.5A CN202110315805A CN113051055A CN 113051055 A CN113051055 A CN 113051055A CN 202110315805 A CN202110315805 A CN 202110315805A CN 113051055 A CN113051055 A CN 113051055A
Authority
CN
China
Prior art keywords
task
snapshot
snapshots
thread pool
determining whether
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
CN202110315805.5A
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology 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 Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202110315805.5A priority Critical patent/CN113051055A/en
Publication of CN113051055A publication Critical patent/CN113051055A/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/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Quality & Reliability (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a task processing method and a task processing device, and relates to the technical field of computers. One embodiment of the method comprises: determining whether a task snapshot needs to be written, and if so, serializing the tasks in the thread pool to obtain the task snapshot; storing the task snapshot; determining whether the task snapshot needs to be restored, and if so, reading the task snapshot; deserializing the task snapshot to obtain the task; submitting the task to the thread pool. The implementation method can reduce the waiting time required by closing the service, quickly recover the task execution and prevent the task from being lost.

Description

Task processing method and device
Technical Field
The invention relates to the technical field of computers, in particular to a task processing method and a task processing device.
Background
In the back-end development process, a thread pool is generally adopted to process tasks in parallel. When a service needs to be restarted or redeployed, in order to ensure that tasks in the thread pool are not lost, the prior art processes the remaining tasks in the thread pool through a callback function.
Specifically, after receiving a service closing signal, the hook thread checks whether an unexecuted task exists in the thread pool, if so, the thread pool continues to execute the task, otherwise, the hook thread notifies the service closing. That is to say, in the prior art, the service can be closed only after the execution of the tasks in the thread pool is finished, and if there are many tasks or there is a problem in the execution process, it takes a long time to close the service.
Disclosure of Invention
In view of this, embodiments of the present invention provide a task processing method and apparatus, which can reduce the waiting time required for closing a service, quickly recover task execution, and prevent task loss.
In a first aspect, an embodiment of the present invention provides a task processing method, including:
determining whether a task snapshot needs to be written, and if so, serializing the tasks in the thread pool to obtain the task snapshot;
storing the task snapshot;
determining whether the task snapshot needs to be restored, and if so, reading the task snapshot;
deserializing the task snapshot to obtain the task;
submitting the task to the thread pool.
Alternatively,
the determining whether the task snapshot needs to be written includes:
determining whether the state of a preset snapshot state machine is open;
the determining whether the task snapshot needs to be restored includes:
determining whether the state of the snapshot state machine is off.
Alternatively,
the storing the task snapshot includes:
adding a plurality of task snapshots to a memory;
writing the plurality of task snapshots in the memory into a specified file of a disk;
the reading the task snapshot includes:
and reading a plurality of task snapshots from the specified file of the disk, and adding the task snapshots into a memory.
Alternatively,
the storing the task snapshot includes:
adding a plurality of task snapshots to a memory;
writing the plurality of task snapshots in the memory into a designated file of a database;
the reading the task snapshot includes:
and reading a plurality of task snapshots from the specified file of the database, and adding the task snapshots into a memory.
Alternatively,
after the submitting the task into the thread pool, further comprising:
and deleting the stored task snapshot.
Alternatively,
in the memory, the plurality of task snapshots are stored in a list data structure with locks.
Alternatively,
the determining whether the task snapshot needs to be written includes:
determining whether the service needs to be shut down;
the determining whether the task snapshot needs to be restored includes:
determining whether the service is started.
In a second aspect, an embodiment of the present invention provides a task processing apparatus, including:
the writing module is configured to determine whether a task snapshot needs to be written, and if so, serialize the tasks in the thread pool to obtain the task snapshot;
a storage module configured to store the task snapshot;
the recovery module is configured to determine whether the task snapshot needs to be recovered, and if so, read the task snapshot; deserializing the task snapshot to obtain the task;
a submission module configured to submit the task to the thread pool.
In a third aspect, an embodiment of the present invention provides an electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement a method as in any one of the embodiments described above.
In a fourth aspect, the present invention provides a computer readable medium, on which a computer program is stored, and when the program is executed by a processor, the computer program implements the method according to any one of the above embodiments.
One embodiment of the above invention has the following advantages or benefits: under the condition that services or thread pools need to be closed, the method can convert uncompleted tasks in the thread pools into task snapshots through serialization and store the task snapshots; when the service or the thread pool is started, and the like, the task snapshot is converted into the task through deserialization and submitted into the thread pool, so that the thread pool continues to execute the task. The method can reduce the waiting time for closing the service or thread pool, quickly recover the task execution and avoid the task loss.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a flow diagram of a thread pool executing tasks according to an embodiment of the invention;
FIG. 2 is a flow chart of a closing a container according to an embodiment of the present invention;
FIG. 3 is a flow diagram of a method for task processing according to an embodiment of the invention;
FIG. 4 is a flow diagram of a method for task processing according to another embodiment of the invention;
FIG. 5 is a schematic diagram of a task processing device according to an embodiment of the present invention;
FIG. 6 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 7 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
In the back-end development process, a thread pool is often required to process tasks in parallel. As shown in fig. 1, a task to be processed is submitted to a buffer queue of a thread pool, and the task is pulled from the buffer queue by a different thread and processed.
And under the scenes that the container needs to be restarted or redeployed and the like, partial tasks in the thread pool are not completed. To ensure that tasks complete smoothly, the prior art is generally based on a hook mechanism to handle uncompleted tasks in a thread pool. The specific process is as shown in fig. 2, after receiving a service closing signal, the hook thread checks whether an unexecuted task exists in the thread pool, if so, the thread pool continues to execute the task, otherwise, the hook thread notifies the service closing.
However, the prior art may face the following situations in the implementation process:
(1) the number of tasks in the thread pool is large, and a large amount of time is consumed for processing and completing the tasks;
(2) the number of tasks in the thread pool is small, and the tasks need to consume a long time;
(3) the number of tasks in the thread pool is small, but a certain flow on which the task processing depends is problematic.
This leads to a long time spent by the thread pool to complete the task processing, and thus the container needs to wait for a long time to close.
In view of this, as shown in fig. 3, an embodiment of the present invention provides a task processing method, including:
step 301: and when the task snapshot is determined to be required to be written, serializing the tasks in the thread pool to obtain the task snapshot.
In the embodiment of the present invention, a snapshot writing condition may be configured in advance, and when the snapshot writing condition is satisfied, a snapshot writing process is executed, that is, tasks in a thread pool are serialized, and subsequent steps are executed. For example, when the time for the thread pool to execute the target task exceeds a preset value, the tasks in the thread pool are serialized. The thread pool takes a long time to execute the target task, which indicates that a problem may occur in the execution process of the target task, at this time, the snapshot write process may be executed, and then the thread pool is restarted.
In the embodiment of the present invention, the snapshot write process may also be executed when a specified event is monitored. For example, when a closing signal of a container or an application is monitored, tasks in the thread pool are serialized to obtain a task snapshot. Therefore, under different application scenarios, when the task in the thread pool needs to be suspended, the task can be saved in the form of a task snapshot so as to facilitate the subsequent resuming of execution.
Step 302: and storing the task snapshot.
Step 303: and reading the task snapshot when the task snapshot is determined to need to be restored.
In the embodiment of the present invention, the snapshot recovery process may be executed when a specific event is monitored. For example, when a start signal of a container or an application is listened to, a task snapshot is read. Therefore, under different application scenarios, when the execution task needs to be resumed, the task snapshot can be deserialized, and the obtained task is submitted to the thread pool to be continuously executed.
Step 304: and performing deserialization on the task snapshot to obtain a task.
Step 305: the task is submitted to the thread pool.
Under the condition that services or thread pools need to be closed, the method can convert uncompleted tasks in the thread pools into task snapshots through serialization and store the task snapshots; when the service or the thread pool is started, and the like, the task snapshot is converted into the task through deserialization and submitted into the thread pool, so that the thread pool continues to execute the task. The method can reduce the waiting time for closing the service or thread pool, quickly recover the task execution and avoid the task loss.
In the embodiment of the present invention, determining whether a task snapshot needs to be written includes: determining whether the state of a preset snapshot state machine is open;
determining whether a task snapshot needs to be restored, comprising: it is determined whether the state of the snapshot state machine is off.
In the embodiment of the invention, the states of the snapshot state machine comprise two states, namely opening and closing, and the snapshot state machine is respectively and correspondingly written into the task snapshot and restored to the task snapshot.
The embodiment of the invention identifies whether to write the task snapshot or recover the task snapshot through the state of the snapshot state machine. In an actual application scenario, a technician changes the state of the snapshot state machine as needed. The state of the snapshot state machine may also be determined by the listening process, e.g., when it is listened that the application is open, the listening process modifies the state of the snapshot state machine to be closed. The embodiment of the invention accurately executes the task snapshot writing and recovery process through the snapshot state machine, and quickly recovers the task execution.
In one embodiment of the invention, storing a task snapshot includes: adding a plurality of task snapshots to a memory; writing a plurality of task snapshots in a memory into a specified file of a disk;
reading a task snapshot, comprising: and reading a plurality of task snapshots from a specified file of a disk, and adding the task snapshots into a memory.
The embodiment of the invention sequentially adds a plurality of task snapshots to the memory for temporary storage, and after the task snapshots are all added to the memory, the method writes the task snapshots in the memory into the specified file of the disk once for persistent storage. The task snapshot is written into the disk once, so that the loss of the disk can be reduced, and the writing efficiency is improved. Storing to disk can reduce the consumption of memory resources. In addition, the embodiment of the invention does not depend on a third-party tool, and can reduce the storage cost.
In one embodiment of the invention, storing a task snapshot includes: adding a plurality of task snapshots to a memory; writing a plurality of task snapshots in a memory into a designated file of a database;
reading a task snapshot, comprising: and reading a plurality of task snapshots from a specified file of the database, and adding the task snapshots into a memory.
In the embodiment of the invention, a third-party database can be relied on for the persistent storage of the task snapshot.
In one embodiment of the invention, after the task is committed into the thread pool, the method comprises:
the stored task snapshot is deleted.
In order to avoid the task being repeatedly submitted to the thread pool for execution, after the task is submitted to the thread pool, the task snapshot in a disk, a memory or a database is deleted.
In one embodiment of the invention, in memory, multiple task snapshots are stored in a list data structure with locks.
According to the embodiment of the invention, the task snapshot is stored through the list data structure with the lock, so that the storage safety of the task snapshot can be improved, and the task snapshots are sequentially deserialized.
In one embodiment of the invention, determining whether a task snapshot needs to be written comprises: determining whether the service needs to be shut down;
determining whether a task snapshot needs to be restored, comprising: it is determined whether a service is initiated.
The embodiment of the invention determines whether to write or recover the task snapshot based on the service state, can save the task snapshot in time when the service needs to be closed, and can recover the task execution after the service is restarted or redeployed, thereby ensuring that the task is not lost.
As shown in fig. 4, an embodiment of the present invention provides a task processing method, where the method includes:
step 401: when the preset snapshot state machine is determined to be started, serializing a plurality of tasks in the thread pool respectively to obtain a plurality of task snapshots.
The embodiment of the invention defines whether to generate the task snapshot or not through the preset snapshot state machine snapshortFlag. When the snapport flag is true, the state of the snapshot state machine is open, and when the sna pshortFlag is false, the state of the snapshot state machine is closed. Taking the service restart as an example, when the service needs to be closed, the snapport flag is changed to true, and when the service is started, the snapo rtFlag is changed to false.
And when the snapshortFlag is true, executing the shutdownmethod of the thread pool, wherein the thread pool does not receive new tasks any more and only processes the tasks in the cache queue.
Step 402: adding a plurality of task snapshots to a memory.
Multiple task snapshots are added to the synchronized list collection for staging.
Step 403: and writing the plurality of task snapshots in the memory into a specified file of a disk.
Dump a task snapshot in the syncronizidlist set is written once in the specified file task.
Step 404: and when the state of the snapshot state machine is determined to be closed, reading a plurality of task snapshots from the specified file of the disk and adding the task snapshots into the memory.
And when the snapshortFlag is false, checking whether a task snapshot exists in the task.dump of the disk, and if so, reading the task snapshot into the memory.
Step 405: and performing deserialization on the plurality of task snapshots to obtain a plurality of tasks.
Step 406: and submitting a plurality of tasks into the thread pools respectively.
Step 407: and deleting the stored task snapshot after the plurality of tasks are submitted to the thread pool.
Step 401-step 403 is a write task snapshot process, and step 404-step 407 is a restore task snapshot process.
In a scene that the task of the thread pool needs to be temporarily stored, the embodiment of the invention can prevent the task from being lost by writing the task snapshot, when the thread pool resumes execution, the task snapshot is recovered, and the task is submitted to the thread pool to continue execution. The embodiment of the invention can realize task temporary storage and quick task recovery by writing and recovering the task snapshot, and avoid long-time waiting.
As shown in fig. 5, an embodiment of the present invention provides a task processing apparatus, including:
the writing module 501 is configured to determine whether a task snapshot needs to be written, and if so, serialize the tasks in the thread pool to obtain the task snapshot;
a storage module 502 configured to store a task snapshot;
a recovery module 503, configured to determine whether the task snapshot needs to be recovered, and if so, read the task snapshot; deserializing the task snapshot to obtain a task;
a commit module 504 configured to commit the task to the thread pool.
In an embodiment of the present invention, the writing module 501 is configured to determine whether a state of a preset snapshot state machine is on; a restore module 503 configured to determine whether the state of the snapshot state machine is off.
In an embodiment of the present invention, the storage module 502 is configured to add a plurality of task snapshots to a memory; writing a plurality of task snapshots in a memory into a specified file of a disk;
the recovery module 503 is configured to read a plurality of task snapshots from a specified file of the disk, and add the task snapshots to the memory.
In an embodiment of the present invention, the storage module 502 is configured to add a plurality of task snapshots to a memory; writing a plurality of task snapshots in a memory into a designated file of a database;
and the recovery module 503 is configured to read a plurality of task snapshots from the specified file of the database and add the task snapshots to the memory.
In one embodiment of the invention, the commit module 504 is configured to delete a stored task snapshot.
In one embodiment of the invention, in memory, multiple task snapshots are stored in a list data structure with locks.
In one embodiment of the invention, the writing module 501 is configured to determine whether a service needs to be shut down; a recovery module 503 configured to determine whether a service is started.
An embodiment of the present invention provides an electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the method of any of the embodiments as described above.
An embodiment of the present invention provides a computer-readable medium, on which a computer program is stored, where the computer program is characterized in that when being executed by a processor, the computer program implements the method according to any one of the above embodiments.
Fig. 6 shows an exemplary system architecture 600 of a task processing method or a task processing device to which an embodiment of the present invention can be applied.
As shown in fig. 6, the system architecture 600 may include terminal devices 601, 602, 603, a network 604, and a server 605. The network 604 serves to provide a medium for communication links between the terminal devices 601, 602, 603 and the server 605. Network 604 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 601, 602, 603 to interact with the server 605 via the network 604 to receive or send messages or the like. The terminal devices 601, 602, 603 may have installed thereon various communication client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 601, 602, 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 605 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 601, 602, 603. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the task processing method provided by the embodiment of the present invention is generally executed by the server 605, and accordingly, the task processing device is generally disposed in the server 605.
It should be understood that the number of terminal devices, networks, and servers in fig. 6 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 7, shown is a block diagram of a computer system 700 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 7, the computer system 700 includes a Central Processing Unit (CPU)701, which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. In the RAM 703, various programs and data necessary for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
The following components are connected to the I/O interface 705: an input portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. A drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read out therefrom is mounted into the storage section 708 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 701.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a sending module, an obtaining module, a determining module, and a first processing module. The names of these modules do not form a limitation on the modules themselves in some cases, and for example, the sending module may also be described as a "module sending a picture acquisition request to a connected server".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
determining whether a task snapshot needs to be written, and if so, serializing the tasks in the thread pool to obtain the task snapshot;
storing the task snapshot;
determining whether the task snapshot needs to be restored, and if so, reading the task snapshot;
deserializing the task snapshot to obtain the task;
submitting the task to the thread pool.
According to the technical scheme of the embodiment of the invention, under the scene that the service or the thread pool needs to be closed, the method can convert the tasks which are not finished in the thread pool into the task snapshots through serialization and store the tasks; when the service or the thread pool is started, and the like, the task snapshot is converted into the task through deserialization and submitted into the thread pool, so that the thread pool continues to execute the task. The method can reduce the waiting time for closing the service or thread pool, quickly recover the task execution and avoid the task loss.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A task processing method, comprising:
determining whether a task snapshot needs to be written, and if so, serializing the tasks in the thread pool to obtain the task snapshot;
storing the task snapshot;
determining whether the task snapshot needs to be restored, and if so, reading the task snapshot;
deserializing the task snapshot to obtain the task;
submitting the task to the thread pool.
2. The method of claim 1,
the determining whether the task snapshot needs to be written includes:
determining whether the state of a preset snapshot state machine is open;
the determining whether the task snapshot needs to be restored includes:
determining whether the state of the snapshot state machine is off.
3. The method of claim 1,
the storing the task snapshot includes:
adding a plurality of task snapshots to a memory;
writing the plurality of task snapshots in the memory into a specified file of a disk;
the reading the task snapshot includes:
and reading a plurality of task snapshots from the specified file of the disk, and adding the task snapshots into a memory.
4. The method of claim 3,
the storing the task snapshot includes:
adding a plurality of task snapshots to a memory;
writing the plurality of task snapshots in the memory into a designated file of a database;
the reading the task snapshot includes:
and reading a plurality of task snapshots from the specified file of the database, and adding the task snapshots into a memory.
5. The method of claim 1,
after the submitting the task into the thread pool, further comprising:
and deleting the stored task snapshot.
6. The method of claim 1,
in the memory, the plurality of task snapshots are stored in a list data structure with locks.
7. The method of any one of claims 1-6,
the determining whether the task snapshot needs to be written includes:
determining whether the service needs to be shut down;
the determining whether the task snapshot needs to be restored includes:
determining whether the service is started.
8. A task processing apparatus, comprising:
the writing module is configured to determine whether a task snapshot needs to be written, and if so, serialize the tasks in the thread pool to obtain the task snapshot;
a storage module configured to store the task snapshot;
the recovery module is configured to determine whether the task snapshot needs to be recovered, and if so, read the task snapshot; deserializing the task snapshot to obtain the task;
a submission module configured to submit the task to the thread pool.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN202110315805.5A 2021-03-24 2021-03-24 Task processing method and device Pending CN113051055A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110315805.5A CN113051055A (en) 2021-03-24 2021-03-24 Task processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110315805.5A CN113051055A (en) 2021-03-24 2021-03-24 Task processing method and device

Publications (1)

Publication Number Publication Date
CN113051055A true CN113051055A (en) 2021-06-29

Family

ID=76515056

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110315805.5A Pending CN113051055A (en) 2021-03-24 2021-03-24 Task processing method and device

Country Status (1)

Country Link
CN (1) CN113051055A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113377724A (en) * 2021-07-02 2021-09-10 厦门雅基软件有限公司 Cache space management method, device and storage medium
CN113377723A (en) * 2021-07-02 2021-09-10 厦门雅基软件有限公司 Cache file management method, device and storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101667147A (en) * 2009-07-27 2010-03-10 浪潮电子信息产业股份有限公司 Multitasking controllable automatic snapshot method
CN102622426A (en) * 2012-02-27 2012-08-01 杭州闪亮科技有限公司 Database writing system and database writing method
CN106681840A (en) * 2016-12-30 2017-05-17 郑州云海信息技术有限公司 Tasking scheduling method and device for cloud operating system
CN109271367A (en) * 2018-12-07 2019-01-25 浪潮(北京)电子信息产业有限公司 Distributed file system multinode snapshot rollback method and system
CN111064597A (en) * 2019-11-12 2020-04-24 刘璐豪 Self-healing method of middleware node self-healing system based on Pass platform
CN111343219A (en) * 2018-12-18 2020-06-26 同方威视技术股份有限公司 Computing service cloud platform
CN111752545A (en) * 2020-06-25 2020-10-09 武汉众邦银行股份有限公司 Stream computing method supporting data replay
CN112148498A (en) * 2020-09-30 2020-12-29 平安普惠企业管理有限公司 Data synchronization method, device, server and storage medium

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101667147A (en) * 2009-07-27 2010-03-10 浪潮电子信息产业股份有限公司 Multitasking controllable automatic snapshot method
CN102622426A (en) * 2012-02-27 2012-08-01 杭州闪亮科技有限公司 Database writing system and database writing method
CN106681840A (en) * 2016-12-30 2017-05-17 郑州云海信息技术有限公司 Tasking scheduling method and device for cloud operating system
CN109271367A (en) * 2018-12-07 2019-01-25 浪潮(北京)电子信息产业有限公司 Distributed file system multinode snapshot rollback method and system
CN111343219A (en) * 2018-12-18 2020-06-26 同方威视技术股份有限公司 Computing service cloud platform
CN111064597A (en) * 2019-11-12 2020-04-24 刘璐豪 Self-healing method of middleware node self-healing system based on Pass platform
CN111752545A (en) * 2020-06-25 2020-10-09 武汉众邦银行股份有限公司 Stream computing method supporting data replay
CN112148498A (en) * 2020-09-30 2020-12-29 平安普惠企业管理有限公司 Data synchronization method, device, server and storage medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113377724A (en) * 2021-07-02 2021-09-10 厦门雅基软件有限公司 Cache space management method, device and storage medium
CN113377723A (en) * 2021-07-02 2021-09-10 厦门雅基软件有限公司 Cache file management method, device and storage medium
CN113377723B (en) * 2021-07-02 2024-04-05 厦门雅基软件有限公司 Cache file management method, device and storage medium

Similar Documents

Publication Publication Date Title
EP4033374A1 (en) Method and device for synchronizing node data
US11494437B1 (en) System and method for performing object-modifying commands in an unstructured storage service
CN113051055A (en) Task processing method and device
CN110555068A (en) Data export method and device
WO2023040612A1 (en) Order processing method and apparatus
CN110851276A (en) Service request processing method, device, server and storage medium
CN112613964A (en) Account checking method, account checking device, account checking equipment and storage medium
US9400819B2 (en) Updating object attributes in a lock-coupled namespace traversal
US8990168B1 (en) Efficient conflict resolution among stateless processes
CN107526838B (en) Method and device for database cluster capacity expansion
CN113760924A (en) Distributed transaction processing method and device
CN111767126A (en) System and method for distributed batch processing
CN116521639A (en) Log data processing method, electronic equipment and computer readable medium
US20230093004A1 (en) System and method for asynchronous backend processing of expensive command line interface commands
US20230014233A1 (en) Serverless Application Function Execution
CN113781154A (en) Information rollback method, system, electronic equipment and storage medium
CN114490050A (en) Data synchronization method and device
CN114374657A (en) Data processing method and device
CN113779451A (en) Page loading method and device
CN113778910A (en) Data cache processing method and device
CN113010279A (en) Application program process processing method and device for mobile terminal and electronic equipment
CN111767113A (en) Method and device for realizing container eviction
CN115826934B (en) Application development system and method
CN115981828B (en) Service message processing method and device
US8484235B2 (en) Dynamically switching the serialization method of a data structure

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