CN113934524A - Asynchronous processing method and device of task, storage medium and electronic device - Google Patents

Asynchronous processing method and device of task, storage medium and electronic device Download PDF

Info

Publication number
CN113934524A
CN113934524A CN202111166729.2A CN202111166729A CN113934524A CN 113934524 A CN113934524 A CN 113934524A CN 202111166729 A CN202111166729 A CN 202111166729A CN 113934524 A CN113934524 A CN 113934524A
Authority
CN
China
Prior art keywords
execution
task
script
scene
asynchronous
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
CN202111166729.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.)
Qingdao Haier Technology Co Ltd
Haier Smart Home Co Ltd
Original Assignee
Qingdao Haier Technology Co Ltd
Haier Smart Home 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 Qingdao Haier Technology Co Ltd, Haier Smart Home Co Ltd filed Critical Qingdao Haier Technology Co Ltd
Priority to CN202111166729.2A priority Critical patent/CN113934524A/en
Publication of CN113934524A publication Critical patent/CN113934524A/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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44568Immediately runnable code
    • 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/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • 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

Landscapes

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

Abstract

The invention discloses a task asynchronous processing method and device, a storage medium and an electronic device, wherein the method comprises the following steps: starting a script main thread under the condition that the script engine finishes initialization, wherein the script main thread is used for providing a running environment of a scene script file; preloading all scene script files of a local scene through the script main thread; acquiring an execution task to be executed, and determining a first scene script file corresponding to the execution task in all scene script files; and the asynchronous architecture program which instructs the script main thread to start carries out asynchronous processing on the execution task according to the first scene script file.

Description

Asynchronous processing method and device of task, storage medium and electronic device
Technical Field
The present invention relates to the field of communications, and in particular, to a method and an apparatus for asynchronous processing of tasks, a storage medium, and an electronic apparatus.
Background
At present, Android devices are generally used for executing a scene script file to solve the problem of operating a Javascript engine at a device side, and in the process of executing the scene script file, in order to realize control over the Android devices, the Javascript engine needs to be started first, then the scene script file is executed, and after the execution of the scene script file is completed, the engine is closed. If the scene script file is executed for a plurality of times, the operations of starting the engine, executing the scene script file and immediately closing the engine must be repeated for a plurality of times. Such an actuator has inevitable drawbacks that cause the following problems:
as the execution frequency of the scene script file increases, the frequent application and frequent release of the memory caused by the increased operation times of starting and closing the engine can cause the memory to become discontinuous, which not only causes the problem of memory fragmentation, but also affects the execution performance of the scene script.
In the related art, an effective solution is not provided yet for the problem of memory fragmentation caused by frequent switching on and off of an engine under the condition that the execution frequency of a scene script file is increased.
Disclosure of Invention
The embodiment of the invention provides a task asynchronous processing method and device, a storage medium and an electronic device, and at least solves the problem of memory fragmentation caused by frequent switching of an engine under the condition that the execution frequency of a scene script file is increased in the related art.
According to an embodiment of the present invention, there is provided an asynchronous processing method of a task, including: starting a script main thread under the condition that the script engine finishes initialization, wherein the script main thread is used for providing a running environment of a scene script file; preloading all scene script files of a local scene through the script main thread; acquiring an execution task to be executed, and determining a first scene script file corresponding to the execution task in all scene script files; and instructing an asynchronous architecture program started by the script main thread to perform asynchronous processing on the execution task according to the first scene script file.
In an exemplary embodiment, the method further includes: under the condition of receiving equipment change information sent by equipment, generating an attribute change task according to equipment change attributes and equipment identifiers carried in the equipment change information; determining a second scene script file corresponding to the attribute change task; and performing preset operation on the second scene script file according to the equipment change attribute so as to update the second scene script file.
In an exemplary embodiment, in a case that device change information sent by a device is received, the method generates an attribute change task according to a device change attribute and a device identifier carried in the device change information, and includes: determining whether the equipment change attribute meets a preset condition, wherein the preset condition at least comprises one of the following conditions: the equipment change attribute is the physical attribute of the mobile terminal; the equipment change attribute is an environmental attribute monitored by the mobile terminal; and generating an attribute change task according to the equipment change attribute and the equipment identification carried in the equipment change information under the condition of meeting a preset condition.
In an exemplary embodiment, obtaining an execution task to be executed, and before determining a first scenario script file corresponding to the execution task in the scenario script file, further includes: determining a plurality of task queues of the execution tasks under the condition that the execution tasks are multiple; determining the execution priority of a plurality of execution tasks in the task queue according to the request type of a preset request, wherein the preset request is used for triggering the execution tasks, and the request type comprises at least one of the following types: manual request, automatic request; and determining the execution sequence of the plurality of execution tasks according to the execution priority.
In an exemplary embodiment, after acquiring an execution task to be executed and determining a first scenario script file corresponding to the execution task from among all scenario script files, the method further includes: acquiring a first execution sequence corresponding to the execution tasks to be executed from the execution sequence; and determining a second execution sequence of the first scene script file in the asynchronous framework program according to the first execution sequence so as to instruct the asynchronous framework program to execute the first scene script file according to the second execution sequence.
In an exemplary embodiment, the asynchronous framework program instructing the script main thread to start asynchronously processing the execution task according to the first scenario script file includes: when the execution sequence of a script file to be executed in the asynchronous framework program is a fixed third execution sequence and the execution tasks are multiple, acquiring the execution time of each execution task in the multiple execution tasks; and executing a plurality of executing tasks in sequence according to the third executing sequence and the executing time of each task.
In an exemplary embodiment, the step of instructing the script main thread to start the asynchronous framework program to perform asynchronous processing on the execution task according to the first scenario script file further includes: under the condition that the execution sequence of the script file to be executed in the asynchronous framework program is a non-fixed fourth execution sequence, receiving a task execution request for requesting execution of a target task; and acquiring the starting execution time and the ending execution time of the target task, and determining the target execution sequence of the target task in the fourth execution sequence according to the starting execution time and the ending execution time.
According to another embodiment of the present invention, there is also provided an asynchronous processing device for a task, including: the starting module is used for starting a script main thread under the condition that the script engine completes initialization, wherein the script main thread is used for providing a running environment of a scene script file; the preloading module is used for preloading all scene script files of the local scene through the script main thread; the determining module is used for acquiring an execution task to be executed and determining a first scene script file corresponding to the execution task from all the scene script files; and the indicating module is used for indicating the asynchronous architecture program started by the script main thread to carry out asynchronous processing on the execution task according to the first scene script file.
According to a further aspect of the embodiments of the present invention, there is also provided a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the asynchronous processing method of the above task when running.
According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the asynchronous processing method of the task by using the computer program.
In the embodiment of the invention, after all scene script files of a local scene are preloaded through the script main thread, an execution task to be executed is obtained, a first scene script file corresponding to the execution task is determined in all the scene script files, and an asynchronous architecture program started by the script main thread is indicated to carry out asynchronous processing on the execution task according to the first scene script file; by adopting the technical scheme, the problem of memory fragmentation caused by frequent switching on and off of the engine under the condition that the execution frequency of the scene script file is increased is solved, and the execution performance of the scene script file is improved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
fig. 1 is a block diagram of a hardware configuration of a computer terminal of an asynchronous processing method of a task according to an embodiment of the present invention;
FIG. 2 is a flow chart of a method of asynchronous processing of tasks according to an embodiment of the invention;
FIG. 3 is a flow chart of a method of asynchronous processing of tasks according to an embodiment of the invention (two);
FIG. 4 is a schematic diagram of a method of asynchronous processing of tasks according to an embodiment of the invention;
fig. 5 is a block diagram of an asynchronous processing device of a task according to an embodiment of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
The method provided by the embodiment of the application can be executed in a computer terminal or a similar operation device. Taking the example of running on a computer terminal, fig. 1 is a hardware structure block diagram of a computer terminal of an asynchronous task processing method according to an embodiment of the present invention. As shown in fig. 1, the computer terminal may include one or more (only one shown in fig. 1) processors 102 (the processors 102 may include, but are not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, and in an exemplary embodiment, may also include a transmission device 106 for communication functions and an input-output device 108. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration and is not intended to limit the structure of the computer terminal. For example, the computer terminal may also include more or fewer components than shown in FIG. 1, or have a different configuration with equivalent functionality to that shown in FIG. 1 or with more functionality than that shown in FIG. 1.
The memory 104 may be used for storing computer programs, for example, software programs and modules of application software, such as computer programs corresponding to the asynchronous processing method of the task in the embodiment of the present invention, and the processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, so as to implement the method described above. The memory 104 may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to a computer terminal over 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 transmission device 106 is used for receiving or transmitting data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the computer terminal. In one example, the transmission device 106 includes a Network adapter (NIC), which can be connected to other Network devices through a base station so as to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used for communicating with the internet in a wireless manner.
In this embodiment, a task asynchronous processing method is provided, which is applied to the computer terminal, and fig. 2 is a flowchart (a) of a task asynchronous processing method according to an embodiment of the present invention, where the flowchart includes the following steps:
step S202, under the condition that the script engine completes initialization, starting a script main thread, wherein the script main thread is used for providing a running environment of a scene script file;
it should be noted that the script engine may be understood as an interpreter of a computer programming language, which is used for interpreting and translating the execution program text into machine code that can be executed by a computer, for example, a php (hypertext preprocessor) for establishing a website is an object-oriented hypertext preprocessor, which is used for executing a script language on a server side.
In addition, the script engine can also be understood as a virtual machine for processing a script language, such as a JavaScript engine, which is an interpreter for reading and executing JavaScript source codes and a virtual machine for processing JavaScript scripts.
It should be noted that the scene script file may be understood as a scene in different environments, such as a home scene, a leaving scene, or a theater scene in a home environment. The format type of the scene script may be json (javascript Object notification) format.
Step S204, preloading all scene script files of the local scene through the script main thread;
it should be noted that, in step S204, by preloading all the scene script files of the local scene, the execution time in the execution process may be obtained in advance before executing all the scene script files of the local scene, so as to determine the initial execution sequence of executing all the scene script files of the local scene. And under the condition that all scene script files of the local scene only need to be executed, executing all scene script files of the local scene according to the initial execution sequence.
Wherein, the scene script file may be referred to as a scene script for short.
Step S206, acquiring an execution task to be executed, and determining a first scene script file corresponding to the execution task from all scene script files;
it should be noted that the execution task to be executed may be understood as a task that executes the scene script file, and may be automatically started through a program or may be started through responding to an execution request of a target object. The target object may be a human being or a machine, which is not limited in this respect.
In one embodiment, in the case that the target object is a person, the execution request may be a voice command sent by the target object to the device side, such as "turn down the volume of the music player", "turn off the air conditioner", "turn on the water heater", and the like.
And step S208, instructing the asynchronous architecture program started by the script main thread to perform asynchronous processing on the execution task according to the first scene script file.
It should be noted that the asynchronous framework program can be understood as a time-related processing program, for example, an asynchronous framework program based on libov's web library can implement functions such as a timer and asynchronous access to a file system. The Libuv is a cross-platform asynchronous io library based on event driving, and comprises events such as processes, threads, timers and interprocess communication.
Through the steps, under the condition that the script engine completes initialization, starting a script main thread, wherein the script main thread is used for providing a running environment of a scene script file; preloading all scene script files of a local scene through the script main thread; acquiring an execution task to be executed, and determining a first scene script file corresponding to the execution task in all scene script files; and the asynchronous architecture program which instructs the script main thread to start carries out asynchronous processing on the execution task according to the first scene script file, so that the problem of memory fragmentation caused by frequent switching on and off of an engine under the condition that the execution frequency of the scene script file is increased in the related technology is solved, and the execution performance of the scene script file is improved.
In an exemplary embodiment, there is also provided a technical solution, including: under the condition of receiving equipment change information sent by equipment, generating an attribute change task according to equipment change attributes and equipment identifiers carried in the equipment change information; determining a second scene script file corresponding to the attribute change task; and performing preset operation on the second scene script file according to the equipment change attribute so as to update the second scene script file.
It should be noted that the preset operation may include operations such as adding a scene script file, deleting a scene script file, and modifying a script scene file, which is not limited in this disclosure.
It should be noted that the device change information may be understood as instruction information received by the mobile terminal. Under the condition that the household appliance is the equipment, a user can control the household appliance by sending equipment change information through the mobile terminal, and the household appliance can comprise a music player, an intelligent water heater, an intelligent air conditioner and the like.
In one embodiment, the device may be a music player, and if the music player receives the command information of "volume up", the device change information is "volume up".
In an exemplary embodiment, a technical solution for generating an attribute change task according to a device change attribute and a device identifier carried in device change information when the device change information sent by a device is received is provided, and includes: determining whether the equipment change attribute meets a preset condition, wherein the preset condition at least comprises one of the following conditions: the equipment change attribute is the physical attribute of the mobile terminal; the equipment change attribute is an environmental attribute monitored by the mobile terminal; and generating an attribute change task according to the equipment change attribute and the equipment identification carried in the equipment change information under the condition of meeting a preset condition.
It should be noted that the physical attributes of the mobile terminal may include an electric quantity of the mobile terminal, a consumable material of the mobile terminal, a service life of the mobile terminal, and the like.
In one embodiment, in the case that the physical attribute of the mobile terminal is the electric quantity of the mobile terminal, if the current electric quantity value of the mobile terminal is lower than the working electric quantity value, the attribute change task of "charging" is generated according to the current electric quantity value of the mobile terminal and the device identifier. For example, the device identifier of the mobile terminal is ID0A, the current electric quantity value of the mobile terminal is 200mA, the working electric quantity value of the mobile terminal is 300mA, and an attribute change task for charging the mobile terminal corresponding to ID0A is generated.
In one embodiment, in the case that the physical attribute of the mobile terminal is the service life of the mobile terminal, if the current life value of the mobile terminal is greater than the preset life value, the attribute of "scrapping" generated according to the current life value of the mobile terminal and the device identifier is changed into the task. For example, the device identifier of the mobile terminal is ID0B, the current life value of the mobile terminal is 20 years, the preset life value of the mobile terminal is 18 years, and an attribute change task of discarding the mobile terminal corresponding to ID0B is generated.
It should be noted that the environmental attributes may include weather and geography of the environment in which the mobile terminal is located. The weather can be determined through information such as humidity, temperature and pollution degree obtained by a sensor of the mobile terminal, and the geographic position of the mobile terminal can also be obtained through a positioning system of the mobile terminal.
In an exemplary embodiment, in order to better understand how to obtain the execution task to be executed in step S206, and determine the first scenario script file corresponding to the execution task in the scenario script file, this embodiment provides a technical solution, which includes: determining a plurality of task queues of the execution tasks under the condition that the execution tasks are multiple; determining the execution priority of a plurality of execution tasks in the task queue according to the request type of a preset request, wherein the preset request is used for triggering the execution tasks, and the request type comprises at least one of the following types: manual request, automatic request; and determining the execution sequence of the plurality of execution tasks according to the execution priority.
In one embodiment, the manual request may be set to have priority over the automatic request. And under the condition of receiving a plurality of execution tasks, after the execution sequence of the execution tasks corresponding to the manual request is determined according to the time sequence of receiving the preset request, the execution sequence of the execution tasks corresponding to the automatic request is set.
In addition, with reference to the above embodiments, a technical scheme that the priority of the automatic request is higher than that of the manual request may also be obtained, and the details of the present invention are not described herein.
In an exemplary embodiment, a technical solution after acquiring an execution task to be executed and determining a first scenario script file corresponding to the execution task in all scenario script files is further provided, which includes: acquiring a first execution sequence corresponding to the execution tasks to be executed from the execution sequence; and determining a second execution sequence of the first scene script file in the asynchronous framework program according to the first execution sequence so as to instruct the asynchronous framework program to execute the first scene script file according to the second execution sequence.
In an exemplary embodiment, to better understand how the asynchronous framework program that instructs the script main thread to start in step S208 performs asynchronous processing on the execution task according to the first scenario script file, a technical solution is provided, which includes: when the execution sequence of a script file to be executed in the asynchronous framework program is a fixed third execution sequence and the execution tasks are multiple, acquiring the execution time of each execution task in the multiple execution tasks; and executing a plurality of executing tasks in sequence according to the third executing sequence and the executing time of each task.
In an exemplary embodiment, to better understand that the asynchronous framework program that indicates the script main thread to start in step S208 asynchronously processes the execution task according to the first scenario script file further includes: under the condition that the execution sequence of the script file to be executed in the asynchronous framework program is a non-fixed fourth execution sequence, receiving a task execution request for requesting execution of a target task; and acquiring the starting execution time and the ending execution time of the target task, and determining the target execution sequence of the target task in the fourth execution sequence according to the starting execution time and the ending execution time.
In order to better understand the process of the asynchronous processing method of the task, the following describes an implementation method flow of the asynchronous processing of the task with reference to an optional embodiment, but the implementation method flow is not limited to the technical solution of the embodiment of the present invention.
Fig. 3 is a flowchart (ii) of an asynchronous processing method of a task according to an embodiment of the present invention, in this embodiment, there is provided an asynchronous processing method of a task with an application scenario being a home environment, as shown in fig. 3, specifically including the following steps:
step S302: initializing a JavaScript engine;
step S304: starting a Libuv asynchronous framework program;
it should be noted that the asynchronous framework program can be understood as a time-related processing program, for example, an asynchronous framework program based on libov's web library can implement functions such as a timer and asynchronous access to a file system. The Libuv is a cross-platform asynchronous io library based on event driving, and comprises events such as processes, threads, timers and interprocess communication.
Step S306: executing the execution tasks in the task queue;
step S308: loading a scene script file;
it should be noted that, in step S308, all the scene script files of the local scene are preloaded by loading the scene script into the memory, and before all the scene script files of the local scene are executed, the execution time in the execution process may be obtained in advance, so as to determine the initial execution sequence of all the scene script files of the local scene. And under the condition that all scene script files of the local scene only need to be executed, executing all scene script files of the local scene according to the initial execution sequence.
Step S310: executing the scene script file;
step S312: the JavaScript engine is turned off.
In the embodiment of the invention, a user creates different scene scripts for different scenes in a home environment, such as a home scene, a leaving scene, a cinema scene and the like, after initializing a JavaScript engine, a main thread is started to provide an operating environment for executing the scene script file, and the operating environment is based on an asynchronous framework program, so that the method also has the capability of continuously processing the different scene script files.
Fig. 4 is a schematic diagram of an asynchronous processing method of a task according to an embodiment of the present invention. Before executing the asynchronous processing method of the task as shown in fig. 4, the JavaScript engine is initialized, and the JavaScript main thread is started.
The asynchronous processing method of the task in fig. 4 includes the following steps:
1) preloading all local scene script files created by a user (equivalent to the target object) to a memory;
it should be noted that, if the user performs addition, deletion, and modification operations on the scene script file, the scene script can be updated.
2) The task enters a task queue;
the execution requests are divided into 2 types: manual requests and automatic requests. The multiple execution requests correspond to multiple execution tasks, and the task queue creation can manage the multiple execution tasks, for example, sequencing the execution tasks, newly adding the execution tasks, and the like.
In one embodiment, if the user initiates an execution request from the mobile terminal, a corresponding scenario of a manual request is executed.
3) The JavaScript main thread draws and executes the task;
4) and executing the execution tasks in the task queue.
In one embodiment, if a device change attribute is reported by a device at the home of a user and an attribute change task needs to be added, after the attribute change task is fetched by the JavaScript main thread, the preloaded scene script file is used, and whether the scene script file can be executed is determined according to the fact that the device id (equivalent to the device identifier) is the same as the devId in the preloaded scene script file. The devId in the scene script file can be understood as the unique identifier of the scene script file.
The libov asynchronous frame program started by the JavaScript main thread provides time processing capacity for processing services of a plurality of execution tasks, namely, a user is allowed to perform the following operations: and executing the scene script file corresponding to the request after a preset time period, wherein the preset time period may be 30 seconds, 1 minute, and the like, which is not limited in the present invention.
For example, in an embodiment, when the task queue includes the execution task 1, the execution task 2, and the execution task 3, and the user initiates an execution request for executing the execution task 4, the scene script file corresponding to the execution task 4 may be executed after 30 seconds.
According to the technical scheme provided by the embodiment, the environment scene engine in the related technology is transformed into the JavaScript engine, namely the JavaScript file of the local scene is abstracted into the JSON file, so that the storage space of each scene script file is reduced.
According to the technical scheme provided by the embodiment, the scene script file is executed by starting the JavaScript main thread, so that the problem that the JavaScript engine has to be restarted once when an execution request is added every time is solved, the times of switching the engine are reduced, the application times of the memory are reduced, and the problem of memory fragmentation caused by frequent switching of the engine is solved.
According to the technical scheme provided by the embodiment, asynchronous processing of multiple execution tasks is realized through the Libuv asynchronous frame program started by the JavaScript main thread, and the task execution efficiency is improved.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
Fig. 5 is a block diagram of an asynchronous processing device of a task according to an embodiment of the present invention. As shown in fig. 5, includes:
a starting module 52, configured to start a script main thread when the script engine completes initialization, where the script main thread is used to provide a running environment of a scene script file;
it should be noted that the script engine may be understood as an interpreter of a computer programming language, which is used for interpreting and translating the execution program text into machine code that can be executed by a computer, for example, a php (hypertext preprocessor) for establishing a website is an object-oriented hypertext preprocessor, which is used for executing a script language on a server side.
In addition, the script engine can also be understood as a virtual machine for processing a script language, such as a JavaScript engine, which is an interpreter for reading and executing JavaScript source codes and a virtual machine for processing JavaScript scripts.
It should be noted that the scene script file may be understood as a scene in different environments, such as a home scene, a leaving scene, or a theater scene in a home environment. The format type of the scene script may be json (javascript Object notification) format.
The preloading module 54 is configured to preload all scene script files of the local scene through the script main thread;
it should be noted that, by preloading all scene script files of the local scene, the execution time in the execution process may be obtained in advance before executing all scene script files of the local scene, so as to determine the initial execution sequence of executing all scene script files of the local scene. And under the condition that all scene script files of the local scene only need to be executed, executing all scene script files of the local scene according to the initial execution sequence.
A determining module 56, configured to obtain an execution task to be executed, and determine, in all the scene script files, a first scene script file corresponding to the execution task;
it should be noted that the execution task to be executed may be understood as a task that executes the scene script file, and may be automatically started through a program or may be started through responding to an execution request of a target object. The target object may be a human being or a machine, which is not limited in this respect.
In one embodiment, in the case that the target object is a person, the execution request may be a voice command sent by the target object to the device side, such as "turn down the volume of the music player", "turn off the air conditioner", "turn on the water heater", and the like.
And an indicating module 58, configured to indicate the asynchronous framework program started by the script main thread to perform asynchronous processing on the execution task according to the first scenario script file.
It should be noted that the asynchronous framework program can be understood as a time-related processing program, for example, an asynchronous framework program based on libov's web library can implement functions such as a timer and asynchronous access to a file system. The Libuv is a cross-platform asynchronous io library based on event driving, and comprises events such as processes, threads, timers and interprocess communication.
By the device, under the condition that the script engine completes initialization, a script main thread is started, wherein the script main thread is used for providing a running environment of a scene script file; preloading all scene script files of a local scene through the script main thread; acquiring an execution task to be executed, and determining a first scene script file corresponding to the execution task in all scene script files; and the asynchronous architecture program which instructs the script main thread to start carries out asynchronous processing on the execution task according to the first scene script file, so that the problem of memory fragmentation caused by frequent switching on and off of an engine under the condition that the execution frequency of the scene script file is increased in the related technology is solved, and the execution performance of the scene script file is improved.
Optionally, the asynchronous processing apparatus for the task further includes an update module, where the update module is configured to generate an attribute change task according to the device change attribute and the device identifier carried in the device change information when the device change information sent by the device is received; determining a second scene script file corresponding to the attribute change task; and performing preset operation on the second scene script file according to the equipment change attribute so as to update the second scene script file.
It should be noted that the preset operation may include operations such as adding a scene script file, deleting a scene script file, and modifying a script scene file, which is not limited in this disclosure.
It should be noted that the device change information may be understood as instruction information received by the device. In the embodiment of the present invention, taking the device as a home appliance as an example, the home appliance may include a music player, an intelligent water heater, an intelligent air conditioner, and the like.
In one embodiment, the device may be a music player, a volume up/down switch is provided on the music player, and if the music player receives the command information of "increase volume", the device change information is "increase volume".
Optionally, the asynchronous processing apparatus of the task further includes a condition determining module, where the preset condition determining module is configured to determine whether the device change attribute satisfies a preset condition, where the preset condition at least includes one of: the equipment change attribute is the physical attribute of the mobile terminal; the equipment change attribute is an environmental attribute monitored by the mobile terminal; and generating an attribute change task according to the equipment change attribute and the equipment identification carried in the equipment change information under the condition of meeting a preset condition.
Optionally, the asynchronous processing device of the task further includes a task queue determining module, configured to determine a plurality of task queues for executing the task when the number of the executed tasks is multiple; determining the execution priority of a plurality of execution tasks in the task queue according to the request type of a preset request, wherein the preset request is used for triggering the execution tasks, and the request type comprises at least one of the following types: manual request, automatic request; and determining the execution sequence of the plurality of execution tasks according to the execution priority.
Optionally, the asynchronous processing device of the task further includes an execution module, where the execution module is configured to obtain, from the execution sequence, a first execution sequence corresponding to the execution task to be executed; and determining a second execution sequence of the first scene script file in the asynchronous framework program according to the first execution sequence so as to instruct the asynchronous framework program to execute the first scene script file according to the second execution sequence.
In an exemplary embodiment, the indicating module is further configured to, when an execution sequence of a script file to be executed in the asynchronous framework program is a fixed third execution sequence and the number of the execution tasks is multiple, obtain an execution time of each of the multiple execution tasks; and executing a plurality of executing tasks in sequence according to the third executing sequence and the executing time of each task.
In an exemplary embodiment, the indicating module is further configured to receive a task execution request for requesting execution of a target task when an execution order of script files to be executed in the asynchronous framework program is a non-fixed fourth execution order; and acquiring the starting execution time and the ending execution time of the target task, and determining the target execution sequence of the target task in the fourth execution sequence according to the starting execution time and the ending execution time.
An embodiment of the present invention further provides a storage medium including a stored program, wherein the program executes any one of the methods described above.
Alternatively, in the present embodiment, the storage medium may be configured to store program codes for performing the following steps:
s1, starting a script main thread under the condition that the script engine completes initialization, wherein the script main thread is used for providing a running environment of a scene script file;
s2, preloading all scene script files of the local scene through the script main thread;
s3, acquiring an execution task to be executed, and determining a first scene script file corresponding to the execution task in all scene script files;
and S4, instructing the asynchronous architecture program started by the script main thread to perform asynchronous processing on the execution task according to the first scene script file.
Embodiments of the present invention also provide an electronic device comprising a memory having a computer program stored therein and a processor arranged to run the computer program to perform the steps of any of the above method embodiments.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
Optionally, in this embodiment, the processor may be configured to execute the following steps by a computer program:
s1, starting a script main thread under the condition that the script engine completes initialization, wherein the script main thread is used for providing a running environment of a scene script file;
s2, preloading all scene script files of the local scene through the script main thread;
s3, acquiring an execution task to be executed, and determining a first scene script file corresponding to the execution task in all scene script files;
and S4, instructing the asynchronous architecture program started by the script main thread to perform asynchronous processing on the execution task according to the first scene script file.
Optionally, in this embodiment, the storage medium may include, but is not limited to: various media capable of storing program codes, such as a usb disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk.
Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation manners, and this embodiment is not described herein again.
It will be apparent to those skilled in the art that the modules or steps of the present invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method for asynchronous processing of tasks, comprising:
starting a script main thread under the condition that the script engine finishes initialization, wherein the script main thread is used for providing a running environment of a scene script file;
preloading all scene script files of a local scene through the script main thread;
acquiring an execution task to be executed, and determining a first scene script file corresponding to the execution task in all scene script files;
and instructing an asynchronous architecture program started by the script main thread to perform asynchronous processing on the execution task according to the first scene script file.
2. The method of asynchronous processing of tasks according to claim 1, further comprising:
under the condition of receiving equipment change information sent by equipment, generating an attribute change task according to equipment change attributes and equipment identifiers carried in the equipment change information;
determining a second scene script file corresponding to the attribute change task;
and performing preset operation on the second scene script file according to the equipment change attribute so as to update the second scene script file.
3. The asynchronous task processing method according to claim 2, wherein, in a case of receiving device change information sent by a device, generating an attribute change task according to a device change attribute and a device identifier carried in the device change information includes:
determining whether the equipment change attribute meets a preset condition, wherein the preset condition at least comprises one of the following conditions: the equipment change attribute is the physical attribute of the mobile terminal; the equipment change attribute is an environmental attribute monitored by the mobile terminal;
and generating an attribute change task according to the equipment change attribute and the equipment identification carried in the equipment change information under the condition of meeting a preset condition.
4. The asynchronous task processing method according to claim 1, wherein, before obtaining an execution task to be executed and determining a first scenario script file corresponding to the execution task in the scenario script file, the method further comprises:
determining a plurality of task queues of the execution tasks under the condition that the execution tasks are multiple;
determining the execution priority of a plurality of execution tasks in the task queue according to the request type of a preset request, wherein the preset request is used for triggering the execution tasks, and the request type comprises at least one of the following types: manual request, automatic request;
and determining the execution sequence of the plurality of execution tasks according to the execution priority.
5. The asynchronous task processing method according to claim 4, wherein after acquiring an execution task to be executed and determining a first scenario script file corresponding to the execution task from among the scenario script files, the method further comprises:
acquiring a first execution sequence corresponding to the execution tasks to be executed from the execution sequence;
and determining a second execution sequence of the first scene script file in the asynchronous framework program according to the first execution sequence so as to instruct the asynchronous framework program to execute the first scene script file according to the second execution sequence.
6. The method for asynchronously processing tasks according to claim 1, wherein the step of instructing the asynchronous framework program started by the script main thread to asynchronously process the execution task according to the first scenario script file comprises the steps of:
when the execution sequence of a script file to be executed in the asynchronous framework program is a fixed third execution sequence and the execution tasks are multiple, acquiring the execution time of each execution task in the multiple execution tasks;
and executing a plurality of executing tasks in sequence according to the third executing sequence and the executing time of each task.
7. The method of claim 1, wherein the step of instructing the script main thread to start the asynchronous framework program to asynchronously process the execution task according to the first scenario script file further comprises:
under the condition that the execution sequence of the script file to be executed in the asynchronous framework program is a non-fixed fourth execution sequence, receiving a task execution request for requesting execution of a target task;
and acquiring the starting execution time and the ending execution time of the target task, and determining the target execution sequence of the target task in the fourth execution sequence according to the starting execution time and the ending execution time.
8. An apparatus for asynchronous processing of tasks, comprising:
the starting module is used for starting a script main thread under the condition that the script engine completes initialization, wherein the script main thread is used for providing a running environment of a scene script file;
the preloading module is used for preloading all scene script files of the local scene through the script main thread;
the determining module is used for acquiring an execution task to be executed and determining a first scene script file corresponding to the execution task from all the scene script files;
and the indicating module is used for indicating the asynchronous architecture program started by the script main thread to carry out asynchronous processing on the execution task according to the first scene script file.
9. A computer-readable storage medium, comprising a stored program, wherein the program is operable to perform the method of any one of claims 1 to 7.
10. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to execute the method of any of claims 1 to 7 by means of the computer program.
CN202111166729.2A 2021-09-30 2021-09-30 Asynchronous processing method and device of task, storage medium and electronic device Pending CN113934524A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111166729.2A CN113934524A (en) 2021-09-30 2021-09-30 Asynchronous processing method and device of task, storage medium and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111166729.2A CN113934524A (en) 2021-09-30 2021-09-30 Asynchronous processing method and device of task, storage medium and electronic device

Publications (1)

Publication Number Publication Date
CN113934524A true CN113934524A (en) 2022-01-14

Family

ID=79277774

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111166729.2A Pending CN113934524A (en) 2021-09-30 2021-09-30 Asynchronous processing method and device of task, storage medium and electronic device

Country Status (1)

Country Link
CN (1) CN113934524A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115296947A (en) * 2022-06-28 2022-11-04 青岛海尔科技有限公司 Control command response method and device, storage medium and electronic device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115296947A (en) * 2022-06-28 2022-11-04 青岛海尔科技有限公司 Control command response method and device, storage medium and electronic device
CN115296947B (en) * 2022-06-28 2024-01-26 青岛海尔科技有限公司 Control command response method and device, storage medium and electronic device

Similar Documents

Publication Publication Date Title
CN112073471B (en) Control method and device of equipment, storage medium and electronic device
CN110413346A (en) A kind of parameter updating method and device
CN112612214B (en) Method and system for generating functional interface and electronic equipment
CN109614101B (en) Page generation method, system, device, computer equipment and storage medium
CN109561002B (en) Voice control method and device for household electrical appliance
CN112596768B (en) Updating method and device of equipment, storage medium and electronic device
CN112632420A (en) Interface skipping method and device, storage medium and electronic device
CN113934524A (en) Asynchronous processing method and device of task, storage medium and electronic device
CN107526584B (en) Data access method and device
CN114546588A (en) Task deployment method and device, storage medium and electronic device
CN114697150A (en) Command issuing method and device, storage medium and electronic device
CN112671572B (en) Method and device for intelligent equipment network distribution, storage medium and electronic device
CN109086115B (en) Android animation execution method, device, terminal and readable medium
CN113596235B (en) Operation instruction issuing method and device, storage medium and electronic device
CN104216780A (en) Control method and control device for application program association operation
CN108931923B (en) Device control method and apparatus, storage medium, and electronic apparatus
CN105573833A (en) Method and apparatus for processing client application and mobile terminal
CN111831380A (en) Task execution method and device, storage medium and electronic device
CN110188490B (en) Method and device for improving data simulation efficiency, storage medium and electronic device
CN114461399A (en) Resource allocation method and device, storage medium and electronic device
CN114296359A (en) Device control system, method, apparatus, electronic device, storage medium
CN112416195A (en) Method and device for generating device control function
CN116068907A (en) Equipment operation testing method and device, storage medium and electronic device
CN113452588A (en) Display method and device of equipment binding list, storage medium and electronic device
CN115729885A (en) Device grouping method and apparatus, storage medium, and electronic apparatus

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