CN111381961A - Method and device for processing timing task and electronic equipment - Google Patents

Method and device for processing timing task and electronic equipment Download PDF

Info

Publication number
CN111381961A
CN111381961A CN201910282097.2A CN201910282097A CN111381961A CN 111381961 A CN111381961 A CN 111381961A CN 201910282097 A CN201910282097 A CN 201910282097A CN 111381961 A CN111381961 A CN 111381961A
Authority
CN
China
Prior art keywords
task
timing
timed
executed
timer
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
CN201910282097.2A
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.)
Shenzhen Honghe Innovation Information Technology Co Ltd
Original Assignee
Shenzhen Honghe Innovation 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 Shenzhen Honghe Innovation Information Technology Co Ltd filed Critical Shenzhen Honghe Innovation Information Technology Co Ltd
Priority to CN201910282097.2A priority Critical patent/CN111381961A/en
Publication of CN111381961A publication Critical patent/CN111381961A/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/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method and a device for processing a timing task and electronic equipment. The method for processing the timing task comprises the following steps: loading timing task data; establishing a timing task and a timer according to the timing task data; screening the timing task meeting the execution condition as a task to be executed when the timer is triggered; and executing the task to be executed. The device for processing the timing task comprises: the task loading module is used for loading the timing task data; the timing module is used for establishing a timing task and a timer according to the timing task data; the screening module is used for screening the timed task meeting the execution condition as a task to be executed when the timer is triggered; and the execution module is used for executing the task to be executed. The electronic device comprises a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method of processing timed tasks when executing the program.

Description

Method and device for processing timing task and electronic equipment
Technical Field
The present invention relates to the field of computers, and in particular, to a method and an apparatus for processing a timing task, and an electronic device.
Background
In the process of developing an application using JAVA, it is often necessary to perform some periodic operations, or perform some operation at a certain point in time. The most convenient and simple implementation for such an operation is to use the java. Both Timer and TimerTask classes can be found in the java. The Timer class inherits directly from the Object class and can be used to specify a certain time to execute a task or to repeatedly execute the same task at regular intervals. After creating a Timer class, a thread is generated to control the execution of tasks. The TimerTask class is the class used to implement a task.
The prior timing task for solving the above periodic or specific time point operation mainly adopts a Quartz task scheduling framework. The use of the framework can trigger according to the specific set time, and the triggering condition of the time can be very complex (such as 17:50 of the last working day of each month), and the setting of various times can be met. However, the Quartz time trigger condition is generally known, the preset time trigger condition is required to be set, the set time trigger condition is fixed, and Quartz does not support the unfixed time trigger condition freely set by the user.
When the task with the unfixed time trigger condition freely set by the user needs to create a corresponding Timer class, but when the number of the timed tasks with the unfixed time trigger condition freely set by the user is large, a large number of Timer classes must be created to execute the tasks, so that a large number of threads are necessarily generated, the great waste of computer resources is caused, and the problems of system blockage, even abnormal service and the like are often caused.
Disclosure of Invention
In view of the above, an object of the present invention is to provide a method, an apparatus, and an electronic device, which can process a large number of timing tasks with time trigger conditions freely set by users, improve computer resource utilization, and reduce system failure risk.
Based on the above object, the present invention provides a method for processing a timing task, comprising:
loading timing task data;
establishing a timing task and a timer according to the timing task data;
screening the timing task meeting the execution condition as a task to be executed when the timer is triggered;
and executing the task to be executed.
Optionally, the creating a timing task according to the timing task data includes:
determining a specific rule of the timing task according to business logic in the timing task data;
creating the timing task according to the specific rule;
and storing the task information of the timing task into a memory and an external storage unit, and keeping the task information in the memory and the external storage unit consistent.
Optionally, the creating a timing task according to the timing task data further includes:
setting the priority of the timed task according to the timed task data;
and obtaining the classification attribute information of the timing task according to the timing task data, and classifying the timing task according to the classification attribute information.
Optionally, the creating a timer according to the timing task data includes:
determining a specific rule of the timing task according to business logic in the timing task data;
setting triggering time and frequency according to specific rules of different timing tasks;
and creating the timer according to the trigger time and the frequency.
Optionally, the creating a timer according to the timing task data includes:
after the timed tasks are classified according to the classification attribute information, setting triggering time and frequency corresponding to the different types of timed tasks according to the specific rules of the different types of timed tasks, and creating the timer according to the triggering time and the frequency;
configuring a timer separately for the timing tasks of a particular priority.
Optionally, when the timer is triggered, screening out the timing task meeting the execution condition as a task to be executed, including:
when the timer is triggered, reading the task information in the memory;
judging whether the corresponding timing task meets the execution condition or not according to the task information at the current timer triggering time;
and screening the timing task meeting the execution condition as the task to be executed, and adding the task to be executed into an execution queue.
Optionally, when the timer is triggered, the method of screening out the timing task meeting the execution condition as the task to be executed further includes:
when the task information exceeds a preset threshold value, screening the timing task in a multi-thread segmentation processing mode;
and when the tasks to be executed are added into the execution queue, the tasks to be executed are put into the execution queue according to the sequence from high priority to low priority.
Optionally, the executing the task to be executed includes:
executing the task to be executed by utilizing a thread pool in a multi-thread concurrent processing mode;
putting the tasks to be executed with abnormal or failed execution into an execution queue again;
and for the task to be executed which lacks the data required by execution, acquiring corresponding task information from the external storage unit and executing the task information.
In view of the above object, the present invention provides an apparatus for processing a timing task, comprising:
the task loading module is used for loading the timing task data;
the timing module is used for establishing a timing task and a timer according to the timing task data;
the screening module is used for screening the timed task meeting the execution condition as a task to be executed when the timer is triggered;
and the execution module is used for executing the task to be executed.
Optionally, the creating, by the timing module, a timing task according to the timing task data includes:
determining a specific rule of the timing task according to business logic in the timing task data;
creating the timing task according to the specific rule;
and storing the task information of the timing task into a memory and an external storage unit, and keeping the task information in the memory and the external storage unit consistent.
Optionally, the timing module creates a timing task according to the timing task data, and further includes:
setting the priority of the timed task according to the timed task data;
and obtaining the classification attribute information of the timing task according to the timing task data, and classifying the timing task according to the classification attribute information.
Optionally, the creating, by the timing module, a timer according to the timing task data includes:
determining a specific rule of the timing task according to business logic in the timing task data;
setting triggering time and frequency according to specific rules of different timing tasks;
and creating the timer according to the trigger time and the frequency.
Optionally, the creating, by the timing module, a timer according to the timing task data includes:
after the timed tasks are classified according to the classification attribute information, setting triggering time and frequency corresponding to the different types of timed tasks according to the specific rules of the different types of timed tasks, and creating the timer according to the triggering time and the frequency;
configuring a timer separately for the timing tasks of a particular priority.
Optionally, when the timer is triggered, the screening module screens out the timing task that meets the execution condition as a task to be executed, including:
when the timer is triggered, reading the task information in the memory;
judging whether the corresponding timing task meets the execution condition or not according to the task information at the current timer triggering time;
and screening the timing task meeting the execution condition as the task to be executed, and adding the task to be executed into an execution queue.
Optionally, when the timer is triggered, the screening module screens out the timed task meeting the execution condition as a task to be executed, and further includes:
when the task information exceeds a preset threshold value, screening the timing task in a multi-thread segmentation processing mode;
and when the tasks to be executed are added into the execution queue, the tasks to be executed are put into the execution queue according to the sequence from high priority to low priority.
Optionally, the executing module executes the task to be executed, including:
executing the task to be executed by utilizing a thread pool in a multi-thread concurrent processing mode;
putting the tasks to be executed with abnormal or failed execution into an execution queue again;
and for the task to be executed which lacks the data required by execution, acquiring corresponding task information from the external storage unit and executing the task information.
In view of the above, the present invention also provides an electronic device for processing a timed task, including a memory, a processor and a computer program stored in the memory and running on the processor, wherein the processor implements the method for processing the timed task when executing the program.
From the above description, it can be seen that the present invention provides a method, an apparatus, and an electronic device for processing a timed task, wherein only a single or a few timers are created according to the timed task data, and the timers are triggered continuously. And when the timer is triggered, screening out the timing tasks meeting the execution condition at the current moment from the plurality of timing tasks to execute. By adopting the method, even though a large number of timing tasks with the time triggering conditions freely set by the user are processed, the execution of the tasks can be met by using less computing resources, the waste of computer resources is avoided, the utilization rate of the computer resources is greatly improved, and meanwhile, the fault risk of system blockage and even abnormal service caused by the execution of a large number of threads is reduced.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic diagram illustrating a method for processing a timing task according to an embodiment of the present invention;
fig. 2 is a schematic diagram illustrating a method for creating a timed task according to timed task data in a method for processing a timed task according to an embodiment of the present invention;
fig. 3 is a schematic diagram illustrating a method for creating a timer according to timed task data in a method for processing a timed task according to an embodiment of the present invention;
fig. 4 is a schematic diagram illustrating a method for screening a task to be executed from a timing task in a method for processing the timing task according to an embodiment of the present invention;
FIG. 5 is a diagram illustrating an apparatus for processing a timing task according to an embodiment of the present invention;
fig. 6 is a schematic diagram of an electronic device mechanism for processing a timing task according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to specific embodiments and the accompanying drawings.
It should be noted that all expressions using "first" and "second" in the embodiments of the present invention are used for distinguishing two entities with the same name but different names or different parameters, and it should be noted that "first" and "second" are merely for convenience of description and should not be construed as limitations of the embodiments of the present invention, and they are not described in any more detail in the following embodiments.
In one aspect, the present invention provides a method of processing timed tasks.
As shown in fig. 1, some alternative embodiments of the present invention provide a method for processing a timing task, including:
s1: loading timing task data;
s2: establishing a timing task and a timer according to the timing task data;
s3: screening the timing task meeting the execution condition as a task to be executed when the timer is triggered;
s4: and executing the task to be executed.
The timed task data includes unfixed time trigger condition information freely set by a user and other necessary information, at least one timed task can be created based on the timed task data, and a timer can be created corresponding to a plurality of the timed tasks. Unlike the traditional way of creating a Timer class for each timing task to process, the method for processing the timing task in the application only creates a single or a few timers according to the timing task data, and the timers are continuously triggered. And when the timer is triggered, screening out the timing tasks meeting the execution condition at the current moment from the plurality of timing tasks to execute. By adopting the method, even though a large number of timing tasks with the time triggering conditions freely set by the user are processed, the execution of the tasks can be met by using less computing resources, the waste of computer resources is avoided, the utilization rate of the computer resources is greatly improved, and meanwhile, the fault risk of system blockage and even abnormal service caused by the execution of a large number of threads is reduced.
As shown in fig. 2, in a method for processing a timed task according to some alternative embodiments of the present invention, the creating a timed task according to the timed task data includes:
s201: determining a specific rule of the timing task according to business logic in the timing task data;
the timing task data corresponding to each timing task comprises corresponding business logic information, and specific rules of the timing tasks can be acquired from the logic information, wherein the specific rules comprise unfixed time triggering conditions set by a user and specific operations to be executed after the timing tasks are triggered.
S202: creating the timing task according to the specific rule;
s203: and storing the task information of the timing task into a memory and an external storage unit, and keeping the task information in the memory and the external storage unit consistent.
The method for establishing the timing task according to the timing task data determines the specific rule of the timing task according to the timing task data, establishes the timing task, copies the task information of the established timing task into two parts, and respectively stores the two parts in the internal memory and the external storage unit. The task information of the timing task is stored in the memory, so that the task information data can be conveniently and directly read when the timing task is screened later, the frequency of reading the data again from the external storage unit is reduced, and the task execution efficiency can be improved. In addition, task data may be missing in the subsequent process of executing the timed task, and the external storage unit stores the task information of the timed task, so that the normal execution of the timed task can be ensured.
In the method for processing a timed task provided in some optional embodiments of the present invention, in the process of creating a timed task according to the timed task data, priority setting is also performed on the corresponding timed task according to the timed task data, and the priority of the timed task may be determined according to a corresponding specific rule, or may be set by a user according to an actual requirement;
and acquiring classification attribute information of the corresponding timing task according to the timing task data, and classifying the corresponding timing task according to the classification attribute information.
For example, a timed task whose time unit of the time trigger condition is minute (e.g., a timed task triggered every 5 minutes, a timed task triggered every 30 minutes, or a timed task triggered at 14 hours and 25 minutes, etc.) is classified into one type, and a timed task whose time unit of the time trigger condition is second (e.g., a timed task triggered every 20 seconds, a timed task triggered every 25 seconds, etc.) is classified into one type.
The method for creating the timing task according to the timing task data also sets and classifies the priority of the timing task, and the priority and the classification of the timing task can be referred in the processes of creating the timer and executing the timing task, wherein the high-priority timing task is executed first, the important classification task is executed first, the user requirements are fully considered, and the user experience can be improved.
As shown in fig. 3, in a method for processing a timed task according to some alternative embodiments of the present invention, the creating a timer according to the timed task data includes:
s211: determining a specific rule of the timing task according to business logic in the timing task data;
the timing task data corresponding to each timing task comprises corresponding business logic information, and specific rules of the timing tasks can be acquired from the logic information, wherein the specific rules comprise unfixed time triggering conditions set by a user and specific operations to be executed after the timing tasks are triggered.
S212: setting triggering time and frequency according to specific rules of different timing tasks;
s213: and creating the timer according to the trigger time and the frequency.
The method for creating the Timer according to the timed task data sets the triggering time and the frequency according to the specific rules of a plurality of different timed tasks, the triggering time and the frequency are set according to the time triggering conditions of the different timed tasks, and can also be set according to the requirements of users, and the Timer is run according to the triggering time and the frequency. The method avoids the problems of system blockage and even abnormal service caused by the fact that a large number of threads are needed to execute the timing task in the conventional method for processing the timing task, can reduce the waste of computing resources, and improves the computing efficiency and the resource utilization rate.
In some alternative embodiments of the present invention, a method for processing a timed task, where creating a timer according to the timed task data includes:
after the timed tasks are classified according to the classification attribute information, setting triggering time and frequency corresponding to the different types of timed tasks according to the specific rules of the different types of timed tasks, and creating the timer according to the triggering time and the frequency;
configuring a timer separately for the timing tasks of a particular priority.
The method for establishing the timer according to the timed task data sets the trigger time and frequency of the timer according to the classification and the priority of the timed task. Different from the existing method for processing the timing tasks, each timing task is realized by adopting a Timer class, and in the application, a plurality of timing tasks only need to set one or a few timers which are triggered periodically. The method avoids the problems of system blockage and even abnormal service caused by the fact that a large number of threads are needed to execute the timing task in the conventional method for processing the timing task, can reduce the waste of computing resources, and improves the computing efficiency and the resource utilization rate.
As shown in fig. 4, in a method for processing a timed task according to some alternative embodiments of the present invention, the screening out the timed task that satisfies an execution condition as a task to be executed when the timer is triggered includes:
s301: when the timer is triggered, reading the task information in the memory;
s302: judging whether the corresponding timing task meets the execution condition or not according to the task information at the current timer triggering time;
s303: and screening the timing task meeting the execution condition as the task to be executed, and adding the task to be executed into an execution queue.
The timer is triggered periodically according to set triggering time and frequency, when triggered, task information of all timing tasks is read from a memory, whether the corresponding timing tasks meet execution conditions at the triggering time of the current timer is judged according to the task information of the timing tasks, namely whether the timing tasks need to be executed at the current time is judged, the timing tasks meeting the execution conditions at the current time are screened from all the timing tasks, the screened timing tasks are to-be-executed tasks, and the to-be-executed tasks are added into an execution queue.
In some optional embodiments of the present invention, in a method for processing a timed task, when the timer is triggered, the screening out the timed task that satisfies an execution condition as a task to be executed further includes:
when the task information exceeds a preset threshold value, namely the number of the timing tasks needing to be processed is large, screening a large number of the timing tasks by adopting a multi-thread segmentation processing mode, so that the problem of task execution delay or system blockage possibly caused by the large number of the timing tasks can be avoided, and the task execution efficiency is improved;
and when the tasks to be executed are added into the execution queue, the tasks to be executed are put into the execution queue according to the sequence from high priority to low priority. The timing tasks with high priority are placed in the execution queue according to the method, the timing tasks with low priority are placed in the execution queue after the timing tasks with high priority, and the timing tasks with high priority are executed in the subsequent task execution process.
In some alternative embodiments of the present invention, a method for processing a timing task, where the executing the task to be executed includes:
the task to be executed is executed by using the thread pool in a multi-thread concurrent processing mode, and the task execution efficiency can be greatly improved by adopting the mode; according to the condition that the task execution is abnormal or fails, putting the task to be executed which is abnormal or fails in execution into the execution queue again, and executing again; and for the task to be executed which lacks the data required by execution, acquiring corresponding task information from the external storage unit and executing the task information again, thereby ensuring the normal execution of the timing task.
The method for processing the timing task provided by some optional embodiments of the present invention may further include performing cluster deployment, when the timing task data is loaded, placing the timing task data into a Redis cluster, creating a timing task and a timer according to the timing task data, where the timer is a centralized timer, and performing task screening by uniformly taking task data from the Redis cluster using algorithms such as segment processing and the like in a multi-server cluster deployment manner, or performing processing by using algorithms such as load balancing and the like, so as to reasonably control processing capability of task screening. And uniformly putting the screened tasks into an execution queue for waiting to be executed.
In another aspect, the present invention also provides an apparatus for processing a timed task.
As shown in fig. 5, some alternative embodiments of the present invention provide an apparatus for processing a timing task, including:
the task loading module 1 is used for loading timing task data;
the timing module 2 is used for creating a timing task and a timer according to the timing task data;
the screening module 3 is used for screening the timed task meeting the execution condition as a task to be executed when the timer is triggered;
and the execution module 4 is used for executing the task to be executed.
The timed task data includes unfixed time trigger condition information freely set by a user and other necessary information, at least one timed task can be created based on the timed task data, and a timer can be created corresponding to a plurality of the timed tasks. Unlike the traditional way of creating a Timer class for each timing task to process, the device for processing the timing task in the application only creates a single or a few timers according to the timing task data, and the timers are continuously triggered. And when the timer is triggered, screening out the timing tasks meeting the execution condition at the current moment from the plurality of timing tasks to execute. By adopting the method, even though a large number of timing tasks with the time triggering conditions freely set by the user are processed, the execution of the tasks can be met by using less computing resources, the waste of computer resources is avoided, the utilization rate of the computer resources is greatly improved, and meanwhile, the fault risk of system blockage and even abnormal service caused by the execution of a large number of threads is reduced.
In some alternative embodiments of the present invention, in an apparatus for processing a timed task, the timing module 2 creates a timed task according to the timed task data, including:
determining a specific rule of the timing task according to business logic in the timing task data;
the timing task data corresponding to each timing task comprises corresponding business logic information, and specific rules of the timing tasks can be acquired from the logic information, wherein the specific rules comprise unfixed time triggering conditions set by a user and specific operations to be executed after the timing tasks are triggered.
Creating the timing task according to the specific rule;
and storing the task information of the timing task into a memory and an external storage unit, and keeping the task information in the memory and the external storage unit consistent.
The timing module 2 creates a timing task according to the timing task data, determines the specific rule of the timing task according to the timing task data, creates the timing task, copies the task information of the created timing task into two parts, and respectively stores the two parts in the internal memory and the external storage unit. The task information of the timing task is stored in the memory, so that the task information data can be conveniently and directly read when the timing task is screened later, the frequency of reading the data again from the external storage unit is reduced, and the task execution efficiency can be improved. In addition, task data may be missing in the subsequent process of executing the timed task, and the external storage unit stores the task information of the timed task, so that the normal execution of the timed task can be ensured.
In the device for processing a timing task provided in some optional embodiments of the present invention, in the process of creating a timing task according to the timing task data in the timing module 2, priority setting is also performed on the corresponding timing task according to the timing task data, and the priority of the timing task may be determined according to a corresponding specific rule, or may be set by a user according to an actual requirement;
and acquiring classification attribute information of the corresponding timing task according to the timing task data, and classifying the corresponding timing task according to the classification attribute information.
For example, a timed task whose time unit of the time trigger condition is minute (e.g., a timed task triggered every 5 minutes, a timed task triggered every 30 minutes, or a timed task triggered at 14 hours and 25 minutes, etc.) is classified into one type, and a timed task whose time unit of the time trigger condition is second (e.g., a timed task triggered every 20 seconds, a timed task triggered every 25 seconds, etc.) is classified into one type.
The timing module 2 also sets and classifies the priority of the timing task in the process of establishing the timing task according to the timing task data, and the priority and the classification of the timing task can be referred in the subsequent processes of establishing a timer and executing the timing task, so that the high-priority timing task is executed first, the important classification task is executed first, the user requirements are fully considered, and the user experience can be improved.
In an apparatus for processing a timed task provided in some alternative embodiments of the present invention, the timing module 2 creates a timer according to the timed task data, including:
determining a specific rule of the timing task according to business logic in the timing task data;
the timing task data corresponding to each timing task comprises corresponding business logic information, and specific rules of the timing tasks can be acquired from the logic information, wherein the specific rules comprise unfixed time triggering conditions set by a user and specific operations to be executed after the timing tasks are triggered.
Setting triggering time and frequency according to specific rules of different timing tasks;
and creating the timer according to the trigger time and the frequency.
The timing module 2 creates a Timer according to the timing task data, sets the triggering time and frequency according to the specific rules of a plurality of different timing tasks, the triggering time and frequency are set according to the time triggering conditions of the different timing tasks, or can be set according to the requirements of users, and then the Timer is run according to the triggering time and frequency. The method avoids the problems of system blockage and even abnormal service caused by the fact that a large number of threads are needed to execute the timing task in the conventional method for processing the timing task, can reduce the waste of computing resources, and improves the computing efficiency and the resource utilization rate.
In some alternative embodiments of the present invention, the apparatus for processing a timed task, where the timing module 2 creates a timer according to the timed task data, includes:
after the timed tasks are classified according to the classification attribute information, setting triggering time and frequency corresponding to the different types of timed tasks according to the specific rules of the different types of timed tasks, and creating the timer according to the triggering time and the frequency;
configuring a timer separately for the timing tasks of a particular priority.
And the timing module 2 creates a timer according to the timing task data and sets the trigger time and frequency of the timer according to the classification and priority of the timing task. Different from the existing method for processing the timing tasks, each timing task is realized by adopting a Timer class, and in the application, a plurality of timing tasks only need to set one or a few timers which are triggered periodically. The method avoids the problems of system blockage and even abnormal service caused by the fact that a large number of threads are needed to execute the timing task in the conventional method for processing the timing task, can reduce the waste of computing resources, and improves the computing efficiency and the resource utilization rate.
In some alternative embodiments of the present invention, in an apparatus for processing a timed task, when the timer is triggered, the screening out the timed task that satisfies an execution condition as a task to be executed includes:
when the timer is triggered, reading the task information in the memory;
judging whether the corresponding timing task meets the execution condition or not according to the task information at the current timer triggering time;
and screening the timing task meeting the execution condition as the task to be executed, and adding the task to be executed into an execution queue.
The timer is triggered periodically according to set triggering time and frequency, when triggered, task information of all timing tasks is read from a memory, whether the corresponding timing tasks meet execution conditions at the triggering time of the current timer is judged according to the task information of the timing tasks, namely whether the timing tasks need to be executed at the current time is judged, the timing tasks meeting the execution conditions at the current time are screened from all the timing tasks, the screened timing tasks are to-be-executed tasks, and the to-be-executed tasks are added into an execution queue.
In an apparatus for processing a timed task according to some optional embodiments of the present invention, the screening, when the timer is triggered, the timed task that satisfies an execution condition as a task to be executed further includes:
when the task information exceeds a preset threshold value, namely the number of the timing tasks needing to be processed is large, screening a large number of the timing tasks by adopting a multi-thread segmentation processing mode, so that the problem of task execution delay or system blockage possibly caused by the large number of the timing tasks can be avoided, and the task execution efficiency is improved;
and when the tasks to be executed are added into the execution queue, the tasks to be executed are put into the execution queue according to the sequence from high priority to low priority. The timing tasks with high priority are placed in the execution queue according to the method, the timing tasks with low priority are placed in the execution queue after the timing tasks with high priority, and the timing tasks with high priority are executed in the subsequent task execution process.
In an apparatus for processing a timed task provided in some alternative embodiments of the present invention, the executing module 4 executes the task to be executed, including:
the task to be executed is executed by using the thread pool in a multi-thread concurrent processing mode, and the task execution efficiency can be greatly improved by adopting the mode; according to the condition that the task execution is abnormal or fails, putting the task to be executed which is abnormal or fails in execution into the execution queue again, and executing again; and for the task to be executed which lacks the data required by execution, acquiring corresponding task information from the external storage unit and executing the task information again, thereby ensuring the normal execution of the timing task.
In another aspect, the present invention also provides an electronic device for performing the method of processing a timing task.
As shown in fig. 6, the electronic apparatus includes:
one or more processors 501 and a memory 502, with one processor 501 being an example in fig. 6.
The electronic device performing the method of processing a timing task may further include: an input device 503 and an output device 504.
The processor 501, the memory 502, the input device 503 and the output device 504 may be connected by a bus or other means, and fig. 6 illustrates the connection by a bus as an example.
The memory 502, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions/modules corresponding to the smart shooting method in the embodiments of the present application. The processor 501 executes various functional applications of the server and data processing, i.e., a method of processing a timing task of the above-described method embodiment, by running a nonvolatile software program, instructions, and modules stored in the memory 502.
The memory 502 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to use of a device that performs the method of processing the timing task, and the like. Further, the memory 502 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some embodiments, memory 502 may optionally include memory located remotely from processor 501, which may be connected to member user behavior monitoring devices via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 503 may receive input numeric or character information and generate key signal inputs related to user settings and function control of the method device performing the processing timing task. The output device 504 may include a display device such as a display screen.
The one or more modules are stored in the memory 502 and, when executed by the one or more processors 501, perform the smart photography method of any of the method embodiments described above. The technical effect of the embodiment of the device for executing the method for processing the timing task is the same as or similar to that of any method embodiment.
The apparatus and the electronic device of the foregoing embodiments are used to implement the corresponding method in the foregoing embodiments, and have the beneficial effects of the corresponding method embodiments, which are not described herein again.
Those of ordinary skill in the art will understand that: the discussion of any embodiment above is meant to be exemplary only, and is not intended to intimate that the scope of the disclosure, including the claims, is limited to these examples; within the idea of the invention, also features in the above embodiments or in different embodiments may be combined, steps may be implemented in any order, and there are many other variations of the different aspects of the invention as described above, which are not provided in detail for the sake of brevity.
In addition, well known power/ground connections to Integrated Circuit (IC) chips and other components may or may not be shown within the provided figures for simplicity of illustration and discussion, and so as not to obscure the invention. Furthermore, devices may be shown in block diagram form in order to avoid obscuring the invention, and also in view of the fact that specifics with respect to implementation of such block diagram devices are highly dependent upon the platform within which the present invention is to be implemented (i.e., specifics should be well within purview of one skilled in the art). Where specific details (e.g., circuits) are set forth in order to describe example embodiments of the invention, it should be apparent to one skilled in the art that the invention can be practiced without, or with variation of, these specific details. Accordingly, the description is to be regarded as illustrative instead of restrictive.
While the present invention has been described in conjunction with specific embodiments thereof, many alternatives, modifications, and variations of these embodiments will be apparent to those of ordinary skill in the art in light of the foregoing description. For example, other memory architectures (e.g., dynamic ram (dram)) may use the discussed embodiments.
The embodiments of the invention are intended to embrace all such alternatives, modifications and variances that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, substitutions, improvements and the like that may be made without departing from the spirit and principles of the invention are intended to be included within the scope of the invention.

Claims (17)

1. A method of processing timed tasks, comprising:
loading timing task data;
establishing a timing task and a timer according to the timing task data;
screening the timing task meeting the execution condition as a task to be executed when the timer is triggered;
and executing the task to be executed.
2. The method of claim 1, wherein creating a timed task from the timed task data comprises:
determining a specific rule of the timing task according to business logic in the timing task data;
creating the timing task according to the specific rule;
and storing the task information of the timing task into a memory and an external storage unit, and keeping the task information in the memory and the external storage unit consistent.
3. The method of claim 2, wherein creating a timed task from the timed task data further comprises:
setting the priority of the timed task according to the timed task data;
and obtaining the classification attribute information of the timing task according to the timing task data, and classifying the timing task according to the classification attribute information.
4. The method of claim 1, wherein creating a timer based on the timed task data comprises:
determining a specific rule of the timing task according to business logic in the timing task data;
setting triggering time and frequency according to specific rules of different timing tasks;
and creating the timer according to the trigger time and the frequency.
5. The method of claim 3, wherein creating a timer based on the timed task data comprises:
after the timed tasks are classified according to the classification attribute information, setting triggering time and frequency corresponding to the different types of timed tasks according to the specific rules of the different types of timed tasks, and creating the timer according to the triggering time and the frequency;
configuring a timer separately for the timing tasks of a particular priority.
6. The method according to claim 2, wherein the screening out the timed task meeting the execution condition as the task to be executed when the timer is triggered comprises:
when the timer is triggered, reading the task information in the memory;
judging whether the corresponding timing task meets the execution condition or not according to the task information at the current timer triggering time;
and screening the timing task meeting the execution condition as the task to be executed, and adding the task to be executed into an execution queue.
7. The method according to claim 6, wherein the screening out the timed task satisfying the execution condition as the task to be executed when the timer is triggered further comprises:
when the task information exceeds a preset threshold value, screening the timing task in a multi-thread segmentation processing mode;
and when the tasks to be executed are added into the execution queue, the tasks to be executed are put into the execution queue according to the sequence from high priority to low priority.
8. The method of claim 2, wherein the performing the task to be performed comprises:
executing the task to be executed by utilizing a thread pool in a multi-thread concurrent processing mode;
putting the tasks to be executed with abnormal or failed execution into an execution queue again;
and for the task to be executed which lacks the data required by execution, acquiring corresponding task information from the external storage unit and executing the task information.
9. An apparatus for processing timed tasks, comprising:
the task loading module is used for loading the timing task data;
the timing module is used for establishing a timing task and a timer according to the timing task data;
the screening module is used for screening the timed task meeting the execution condition as a task to be executed when the timer is triggered;
and the execution module is used for executing the task to be executed.
10. The apparatus of claim 9, wherein the timing module creates a timing task from the timing task data, comprising:
determining a specific rule of the timing task according to business logic in the timing task data;
creating the timing task according to the specific rule;
and storing the task information of the timing task into a memory and an external storage unit, and keeping the task information in the memory and the external storage unit consistent.
11. The apparatus of claim 10, wherein the timing module creates a timing task from the timing task data, further comprising:
setting the priority of the timed task according to the timed task data;
and obtaining the classification attribute information of the timing task according to the timing task data, and classifying the timing task according to the classification attribute information.
12. The apparatus of claim 9, wherein the timing module creates a timer based on the timed task data, comprising:
determining a specific rule of the timing task according to business logic in the timing task data;
setting triggering time and frequency according to specific rules of different timing tasks;
and creating the timer according to the trigger time and the frequency.
13. The apparatus of claim 11, wherein the timing module creates a timer based on the timed task data, comprising:
after the timed tasks are classified according to the classification attribute information, setting triggering time and frequency corresponding to the different types of timed tasks according to the specific rules of the different types of timed tasks, and creating the timer according to the triggering time and the frequency;
configuring a timer separately for the timing tasks of a particular priority.
14. The apparatus according to claim 10, wherein the screening module screens out the timed task satisfying the execution condition as the task to be executed when the timer is triggered, and includes:
when the timer is triggered, reading the task information in the memory;
judging whether the corresponding timing task meets the execution condition or not according to the task information at the current timer triggering time;
and screening the timing task meeting the execution condition as the task to be executed, and adding the task to be executed into an execution queue.
15. The apparatus according to claim 14, wherein the screening module screens out the timed task satisfying an execution condition as the task to be executed when the timer is triggered, further comprising:
when the task information exceeds a preset threshold value, screening the timing task in a multi-thread segmentation processing mode;
and when the tasks to be executed are added into the execution queue, the tasks to be executed are put into the execution queue according to the sequence from high priority to low priority.
16. The apparatus of claim 10, wherein the execution module executes the task to be performed, comprising:
executing the task to be executed by utilizing a thread pool in a multi-thread concurrent processing mode;
putting the tasks to be executed with abnormal or failed execution into an execution queue again;
and for the task to be executed which lacks the data required by execution, acquiring corresponding task information from the external storage unit and executing the task information.
17. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the method according to any of claims 1 to 8 when executing the program.
CN201910282097.2A 2019-04-09 2019-04-09 Method and device for processing timing task and electronic equipment Pending CN111381961A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910282097.2A CN111381961A (en) 2019-04-09 2019-04-09 Method and device for processing timing task and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910282097.2A CN111381961A (en) 2019-04-09 2019-04-09 Method and device for processing timing task and electronic equipment

Publications (1)

Publication Number Publication Date
CN111381961A true CN111381961A (en) 2020-07-07

Family

ID=71215106

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910282097.2A Pending CN111381961A (en) 2019-04-09 2019-04-09 Method and device for processing timing task and electronic equipment

Country Status (1)

Country Link
CN (1) CN111381961A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112148447A (en) * 2020-09-22 2020-12-29 京东数字科技控股股份有限公司 Task processing method and system based on risk control and electronic equipment
CN112463348A (en) * 2021-01-27 2021-03-09 北京搜狐新媒体信息技术有限公司 Timed task processing method and device
CN113794740A (en) * 2021-11-16 2021-12-14 亿海蓝(北京)数据技术股份公司 Timer control method and system and readable storage medium
CN115601195A (en) * 2022-10-17 2023-01-13 桂林电子科技大学(Cn) Transaction bidirectional recommendation system and method based on real-time label of power user

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103645909A (en) * 2013-12-30 2014-03-19 中国烟草总公司湖南省公司 Handling method and device for timed task
CN106844043A (en) * 2016-12-29 2017-06-13 北京五八信息技术有限公司 The treating method and apparatus of cluster task
CN106886450A (en) * 2015-12-16 2017-06-23 阿里巴巴集团控股有限公司 Method for scheduling task and system
US20170286167A1 (en) * 2016-03-29 2017-10-05 Alibaba Group Holding Limited Time-based adjustable load balancing

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103645909A (en) * 2013-12-30 2014-03-19 中国烟草总公司湖南省公司 Handling method and device for timed task
CN106886450A (en) * 2015-12-16 2017-06-23 阿里巴巴集团控股有限公司 Method for scheduling task and system
US20170286167A1 (en) * 2016-03-29 2017-10-05 Alibaba Group Holding Limited Time-based adjustable load balancing
CN106844043A (en) * 2016-12-29 2017-06-13 北京五八信息技术有限公司 The treating method and apparatus of cluster task

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
杨秀萍;: "Java定时任务及其在工作流系统中的应用", 现代电子技术, no. 08, 15 April 2011 (2011-04-15) *

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112148447A (en) * 2020-09-22 2020-12-29 京东数字科技控股股份有限公司 Task processing method and system based on risk control and electronic equipment
CN112148447B (en) * 2020-09-22 2024-04-16 京东科技控股股份有限公司 Task processing method and system based on risk control and electronic equipment
CN112463348A (en) * 2021-01-27 2021-03-09 北京搜狐新媒体信息技术有限公司 Timed task processing method and device
CN112463348B (en) * 2021-01-27 2021-06-15 北京搜狐新媒体信息技术有限公司 Timed task processing method and device
CN113794740A (en) * 2021-11-16 2021-12-14 亿海蓝(北京)数据技术股份公司 Timer control method and system and readable storage medium
CN115601195A (en) * 2022-10-17 2023-01-13 桂林电子科技大学(Cn) Transaction bidirectional recommendation system and method based on real-time label of power user
CN115601195B (en) * 2022-10-17 2023-09-08 桂林电子科技大学 Transaction bidirectional recommendation system and method based on real-time label of power user

Similar Documents

Publication Publication Date Title
CN111381961A (en) Method and device for processing timing task and electronic equipment
CN107870845B (en) Management method and system for micro-service architecture application
CN107577694B (en) Data processing method and device based on block chain
US10523580B2 (en) Automatic cloud provisioning based on related internet news and social network trends
WO2016205978A1 (en) Techniques for virtual machine migration
US9176805B2 (en) Memory dump optimization in a system
CN113535367A (en) Task scheduling method and related device
US11301296B2 (en) Memory management based on classification of a software process
WO2024007849A1 (en) Distributed training container scheduling for intelligent computing
CN109783255B (en) Data analysis and distribution device and high-concurrency data processing method
CN113835865A (en) Task deployment method and device, electronic equipment and storage medium
US10608915B2 (en) Providing dynamic latency in an integration flow
CN112486642B (en) Resource scheduling method, device, electronic equipment and computer readable storage medium
CN114629960B (en) Resource scheduling method, device, system, equipment, medium and program product
CN110750312A (en) Hardware resource configuration method and device, cloud side equipment and storage medium
CN110750359A (en) Hardware resource configuration method and device, cloud side equipment and storage medium
CN111930516B (en) Load balancing method and related device
CN113885971A (en) State management method and device based on self-adaptive platform system
JP6189545B2 (en) Network application parallel scheduling to reduce power consumption
CN113032119A (en) Task scheduling method and device, storage medium and electronic equipment
CN114595047A (en) Batch task processing method and device
CN113138772A (en) Method and device for constructing data processing platform, electronic equipment and storage medium
CN117135151B (en) Fault detection method of GPU cluster, electronic equipment and storage medium
CN117421123B (en) GPU resource adjustment method and system, electronic equipment and storage medium
CN116185772B (en) File batch detection method and device

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