CN111443959A - Task execution method and device and server - Google Patents

Task execution method and device and server Download PDF

Info

Publication number
CN111443959A
CN111443959A CN202010227852.XA CN202010227852A CN111443959A CN 111443959 A CN111443959 A CN 111443959A CN 202010227852 A CN202010227852 A CN 202010227852A CN 111443959 A CN111443959 A CN 111443959A
Authority
CN
China
Prior art keywords
plug
class
task
executed
scheduler
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.)
Granted
Application number
CN202010227852.XA
Other languages
Chinese (zh)
Other versions
CN111443959B (en
Inventor
张显良
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kingsoft Cloud Network Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Kingsoft Cloud Network Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN202010227852.XA priority Critical patent/CN111443959B/en
Publication of CN111443959A publication Critical patent/CN111443959A/en
Application granted granted Critical
Publication of CN111443959B publication Critical patent/CN111443959B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • G06F9/44526Plug-ins; Add-ons
    • 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
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

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 provides a task execution method, a task execution device and a task execution server, wherein a task to be executed is received; instantiating the class of the plug-in class loader for the task to be executed through a scheduler to obtain the plug-in class loader corresponding to the task to be executed; loading the plug-in classes required by the task to be executed through the plug-in class loader; instantiating the plug-in class required by the task to be executed to obtain the plug-in corresponding to the task to be executed, and controlling the plug-in to execute the task to be executed through a scheduler. When a plurality of tasks are executed simultaneously, the scheduler can instantiate a plug-in class loader for each task, each plug-in class loader can load the plug-in class required by the corresponding task, and further loads the plug-in of the version corresponding to the task based on the plug-in class corresponding to each task, so that the parallel operation of a plurality of versions of the same plug-in is realized, and the parallel operation requirements of various tasks are met.

Description

Task execution method and device and server
Technical Field
The invention relates to the technical field of task scheduling, in particular to a task execution method, a task execution device and a task execution server.
Background
The task scheduling system comprises three basic elements of a job, a plug-in and a scheduler, wherein the job comprises a specific task, the plug-in is an execution engine of the job, and the scheduler is used for driving the plug-in to execute the corresponding job. In the related art, a plurality of versions of jobs and plug-ins in a system exist simultaneously, and the versions of the plug-ins required by jobs of different versions are different. When the operation needs to be executed, the scheduler loads the plug-in class corresponding to the plug-in of the version required for executing the current operation through the class loader so as to instantiate the plug-in class to obtain the plug-in of the required version, and then the operation is executed through the plug-in.
When a plurality of jobs need to be executed simultaneously, versions of the jobs may be different, and thus versions of required plugins may also be different, but the plugin classes corresponding to plugins of different versions are the same; if a plurality of jobs are to be executed simultaneously, plug-in classes are required to be instantiated into plug-ins of different versions, however, class loading is usually performed through a class loader in a scheduling system, and the same plug-in class cannot be loaded for multiple times by the class loader due to the limitation of a class loading mechanism in Java language, so that plug-in classes corresponding to plug-ins of different versions cannot be loaded simultaneously, different versions of the same plug-in cannot be run simultaneously in the scheduling system, that is, different versions of the same plug-in cannot be executed in parallel, and job requirements of part of tasks are difficult to meet.
Disclosure of Invention
The invention aims to provide a task execution method, a task execution device and a task execution server, so that different versions of the same plug-in can be executed in parallel, and the operation requirements of all tasks are met.
In a first aspect, an embodiment of the present invention provides a method for executing a task, where the method includes: receiving a task to be executed; instantiating the class of a preset plug-in class loader for the task to be executed through a preset scheduler to obtain the plug-in class loader corresponding to the task to be executed; the plug-in class loader is used for loading plug-in classes required by executing tasks to be executed; loading the plug-in classes required by the task to be executed through the plug-in class loader; and instantiating the plug-in class required by the task to be executed to obtain the plug-in corresponding to the task to be executed, and controlling the plug-in through a scheduler to execute the task to be executed.
In an optional implementation manner, before the step of receiving the task to be executed, the method further includes: creating a class loader and a hierarchical relation of the class loader; this type of loader comprises: the system comprises an interface class loader, a plug-in class loader and a scheduler class loader; in the hierarchical relation, the interface class loader is higher than the plug-in class loader and the scheduler class loader in hierarchy; the plug-in class loader is used for loading preset plug-in classes; the scheduler class loader is used for loading a preset scheduler class; the interface class loader is used for loading a preset interface class; and the scheduler obtained after the scheduler class is instantiated controls the plug-in obtained after the plug-in class is instantiated through the interface obtained after the interface class is instantiated.
In an alternative embodiment, the scheduler is obtained by: loading a preset scheduler class through a scheduler class loader; and instantiating and loading the obtained scheduler class to obtain the scheduler.
In an optional implementation manner, before the step of receiving the task to be executed, the method further includes: loading a preset interface class through an interface class loader; instantiating and loading the obtained interface class to obtain an interface; the step of controlling the plug-in by the scheduler includes: if the task to be executed comprises a plurality of tasks, the scheduler controls the plug-in of each task to be executed through the interface so as to execute each task to be executed.
In an optional embodiment, the method further comprises: and if the task to be executed is completely executed, deleting the plug-in class loader corresponding to the task to be executed from the memory through the scheduler.
In a second aspect, an embodiment of the present invention provides an apparatus for executing a task, where the apparatus includes: the task receiving module is used for receiving a task to be executed; the loader instantiation module is used for instantiating the class of a preset plug-in class loader for the task to be executed through a preset scheduler to obtain the plug-in class loader corresponding to the task to be executed; the plug-in class loader is used for loading plug-in classes required by executing tasks to be executed; the class loading module is used for loading the plug-in classes required by the tasks to be executed through the plug-in class loader; and the task execution module is used for instantiating the plug-in class required by the task to be executed to obtain the plug-in corresponding to the task to be executed, and controlling the plug-in through the scheduler to execute the task to be executed.
In an optional embodiment, the apparatus further includes a loader relationship creating module, configured to: creating a class loader and a hierarchical relation of the class loader; this type of loader comprises: the system comprises an interface class loader, a plug-in class loader and a scheduler class loader; in the hierarchical relation, the interface class loader is higher than the plug-in class loader and the scheduler class loader in hierarchy; the plug-in class loader is used for loading preset plug-in classes; the scheduler class loader is used for loading a preset scheduler class; the interface class loader is used for loading a preset interface class; and the scheduler obtained after the scheduler class is instantiated controls the plug-in obtained after the plug-in class is instantiated through the interface obtained after the interface class is instantiated.
In an optional embodiment, the apparatus further includes an interface instantiation module configured to: loading a preset interface class through an interface class loader; instantiating and loading the obtained interface class to obtain an interface; the task execution module is configured to: if the task to be executed comprises a plurality of tasks, the scheduler controls the plug-in of each task to be executed through the interface so as to execute each task to be executed.
In an optional embodiment, the apparatus further includes a loader deleting module, configured to: and if the task to be executed is completely executed, deleting the plug-in class loader corresponding to the task to be executed from the memory through the scheduler.
In a third aspect, an embodiment of the present invention provides a server, including a processor and a memory, where the memory stores machine executable instructions capable of being executed by the processor, and the processor executes the machine executable instructions to implement the task execution method described in any one of the foregoing embodiments.
In a fourth aspect, embodiments of the invention provide a machine-readable storage medium having stored thereon machine-executable instructions that, when invoked and executed by a processor, cause the processor to carry out a method of performing a task as described in any one of the preceding embodiments.
The embodiment of the invention has the following beneficial effects:
the invention provides a task execution method, a task execution device and a task execution server, wherein a task to be executed is received; instantiating the class of a preset plug-in class loader for the task to be executed through a preset scheduler to obtain the plug-in class loader corresponding to the task to be executed; the plug-in class loader is used for loading plug-in classes required by executing tasks to be executed; loading the plug-in classes required by the task to be executed through the plug-in class loader; instantiating the plug-in class required by the task to be executed to obtain the plug-in corresponding to the task to be executed, and controlling the plug-in to execute the task to be executed through a scheduler. In the invention, when a plurality of tasks need to be executed simultaneously, a plug-in class loader is instantiated for each task through a scheduler, so that each plug-in class loader loads the plug-in class required by the corresponding task, the plug-in class is instantiated to obtain the plug-in of the version required by each task, and the scheduler controls the plug-ins of different versions to execute the tasks simultaneously; according to the method, corresponding plug-in classes are loaded through different plug-in class loaders, so that the problem that the same plug-in class cannot be loaded by one class loader for multiple times at the same time is solved, multiple versions of the same plug-in run in parallel, and the parallel operation requirements of various tasks are met.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the invention as set forth above.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
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, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
Fig. 1 is a flowchart of a task execution method according to an embodiment of the present invention;
FIG. 2 is a flow chart of another task execution method provided by an embodiment of the invention;
FIG. 3 is a diagram illustrating a hierarchy of a class loader according to an embodiment of the present invention;
FIG. 4 is a schematic structural diagram of an apparatus for executing a task according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a server according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In view of the problem that different versions of the same plug-in cannot be run simultaneously in one scheduling system in the related art, that is, different versions of the same plug-in cannot be executed in parallel, and it is difficult to meet the job requirements of part of tasks, embodiments of the present invention provide a method, an apparatus, and a server for executing tasks.
In order to facilitate understanding of the embodiment of the present invention, a detailed description is first given of a task execution method disclosed in the embodiment of the present invention, and as shown in fig. 1, the method includes the following specific steps:
step S102, receiving a task to be executed.
The task to be executed may be sent by an external device according to a work requirement, and the external device may be a server or a user terminal. In specific implementation, tasks to be executed in the scheduling system usually have different versions, and therefore each task to be executed needs to be executed through a plug-in corresponding to the version; the version may be a new version or an old version, or may be a higher-level version or a lower-level version, for example, if a task to be executed is a higher-level version, then the plug-in executing the task to be executed should also be a higher-level version.
Step S104, instantiating a preset plug-in class loader class for the task to be executed through a preset scheduler to obtain a plug-in class loader corresponding to the task to be executed; the plug-in class loader is used for loading plug-in classes required by executing tasks to be executed.
The preset plug-in class loader is generally only used for loading plug-in classes, and the scheduler may be responsible for creating the plug-in class loader, that is, when a task to be processed is received, the scheduler may instantiate a class of the plug-in class loader for the task to be executed to obtain the plug-in class loader corresponding to the task to be executed, where instantiation generally refers to a process of creating an object with a class in object-oriented programming as instantiation, and the object may be understood as the plug-in class loader.
The classes of the plug-in class loader are generally used to describe the functions that the plug-in class loader can implement, the methods used to implement the functions, and the like. The plug-in class is generally used to describe functions that can be implemented by the plug-in, methods used for implementing the functions, and the like, and the plug-in class generally has a plurality of types, and each type of plug-in class corresponds to a plurality of versions. The plug-in class loader created by the scheduler can load the plug-in classes required by the task to be executed, and the plug-in classes required by the task to be executed are usually plug-in classes capable of executing corresponding versions of the task to be executed.
And step S106, loading the plug-in classes required by the task to be executed through the plug-in class loader.
In a specific implementation, a plug-in class loader created by a scheduler loads a plug-in class required by a task to be executed, and a process of loading the plug-in class generally reads a file corresponding to the plug-in class into a memory, so that the plug-in class can be instantiated as a plug-in (which may also be referred to as an object of the plug-in class or an instance of the plug-in class).
Step S108, instantiating the plug-in class required by the task to be executed to obtain the plug-in corresponding to the task to be executed, and controlling the plug-in through a scheduler to execute the task to be executed.
Since the plug-in class is a descriptive file, the plug-in class needs to be instantiated as an executable object, which is also the above plug-in. In a specific implementation, the plug-in class required by the task to be executed may be instantiated as a plug-in of a version corresponding to the version of the task to be executed, and then the scheduler controls the plug-in to execute the task to be executed.
If a plurality of tasks to be executed need to be executed simultaneously, each task to be executed is independent, and each task to be executed can be executed through the steps S104 to S108, which can also be understood as that the scheduler can create a plug-in class loader for each task to be executed simultaneously, the plug-in classes that each plug-in class loader can load may be the same or different, and the plug-in classes loaded by the plug-in class loader are the tasks to be executed corresponding to each plug-in class loader.
The task execution method provided by the invention comprises the following steps of firstly receiving a task to be executed; instantiating the class of a preset plug-in class loader for the task to be executed through a preset scheduler to obtain the plug-in class loader corresponding to the task to be executed; the plug-in class loader is used for loading plug-in classes required by executing tasks to be executed; loading the plug-in classes required by the task to be executed through the plug-in class loader; instantiating the plug-in class required by the task to be executed to obtain the plug-in corresponding to the task to be executed, and controlling the plug-in to execute the task to be executed through a scheduler. In the invention, when a plurality of tasks need to be executed simultaneously, a plug-in class is instantiated for each task through a scheduler to be loaded, so that each plug-in class loader loads the plug-in class required by the corresponding task, and the plug-in class is instantiated to obtain the plug-in of the version required by each task, so that the scheduler controls the plug-ins of different versions to execute the tasks simultaneously; according to the method, corresponding plug-in classes are loaded through different plug-in class loaders, so that the problem that the same plug-in class cannot be loaded by one class loader for multiple times at the same time is solved, multiple versions of the same plug-in run in parallel, and the parallel operation requirements of various tasks are met.
The embodiment of the invention also provides another task execution method, which is realized on the basis of the method of the embodiment; the method mainly describes a specific process of creating a class loader and a hierarchical relationship of the class loader (specifically, realized by the following step S202), and a specific process of controlling a plug-in to execute a task by a scheduler on the basis of the hierarchical relationship of the class loader; as shown in fig. 2, the method comprises the following specific steps:
step S202, a class loader and a hierarchical relation of the class loader are created; this type of loader comprises: the system comprises an interface class loader, a plug-in class loader and a scheduler class loader; in the hierarchical relationship, the interface class loader is higher in hierarchy than the plug-in class loader and the scheduler class loader.
The plug-in class loader is used for loading preset plug-in classes; the scheduler class loader is used for loading a preset scheduler class; the interface class loader is used for loading a preset interface class; and the scheduler obtained after the scheduler class is instantiated controls the plug-in obtained after the plug-in class is instantiated through the interface obtained after the interface class is instantiated.
The preset plug-in class generally comprises a plurality of plug-in classes, and each plug-in class corresponds to a different version; the preset scheduler classes can be various, each scheduler class only has one version, usually, one task scheduling system corresponds to a scheduler obtained after instantiation of one scheduler class, and the scheduler can control the plug-in instantiated by the plug-in class to execute the task to be executed.
In a specific implementation, the interface Class loader may be referred to as an application Class loader (ApplicationClass L loader), the plug-in Class loader and the scheduler Class loader may be referred to as a custom Class loader (userlass L loader), and in addition to the above Class loader, an upper Class load of the interface Class loader is also typically included, where a boot Class loader (bootrapclass L loader) and an Extension Class loader (Extension Class L loader) are included to complete loading of classes in the entire scheduling system, as shown in fig. 3, a schematic diagram of a hierarchical relationship of the Class loader is shown, and a path that each Class loader can load in fig. 3 is pre-allocated, that is, a Class that each Class loader can load is pre-set, for example, the boot Class loader and the Extension Class loader may be used for loading JRE (Java Runtime Environment) related classes, and the interface Class loader may be used for loading user-defined classes, and the self-defined Class loader may be used for loading classes by the plug-in Class loader and the plug-in Class scheduler.
In the specific implementation, in the specification of the Java virtual machine, the same class can be loaded in the same class loader only once, and all class loaders need to load classes according to the parental delegation rule, that is, each class loader loads classes, a higher-level class loader is requested to load the classes first, and if the higher-level class loader cannot complete the loading, the current class loader loads the classes. In the scheme, the interface class loader is higher in level than the plug-in class loader and the scheduler class loader, and can separate the loading of the interface class from the implementation class (the plug-in class and the scheduler class can be collectively referred to as the implementation class and used for implementing the execution of the task), that is, the interface class is loaded by the interface class loader with the higher level, the plug-in class is loaded by the plug-in class loader with the lower level, and the scheduler class is loaded by the scheduling class loader with the lower level, so that each class has the corresponding loader to load, and each class cannot be repeatedly loaded, therefore, the scheduler class loaded by the scheduler class loader and the plug-in class loaded by the plug-in class loader can be ensured to correspond to the same interface class in one scheduling operation, meanwhile, the scheduler obtained after the instantiation of the scheduler class can control the plug-in obtained after the instantiation of the plug-in class through the interface obtained after the instantiation of the interface class.
Step S204, loading a preset interface class through the interface class loader; and instantiating and loading the obtained interface class to obtain the interface.
The preset interface classes are usually multiple, and each interface class has a corresponding plug-in class, so that an interface obtained by instantiating the interface class can be converted or a plug-in obtained by instantiating the plug-in class can be transmitted.
Step S206, receiving the task to be executed.
Step S208, loading a preset scheduler class through the scheduler class loader; and instantiating and loading the obtained scheduler class to obtain the scheduler.
When the task to be executed is received, a preset scheduler class is required to be loaded through a scheduler class loader, the scheduler class is used for describing functions which can be realized by the scheduler and realizing a method which can be executed, an example of the scheduler class can be obtained after the scheduler class is instantiated, namely, the scheduler can be obtained, and the scheduler can control the plug-in to execute the task to be executed.
Step S210, instantiating the class of the plug-in class loader for the task to be executed through the scheduler, and obtaining the plug-in class loader corresponding to the task to be executed.
Step S212, loading the plug-in class required by the task to be executed through the plug-in class loader corresponding to the task to be executed.
Step S214, instantiating the plug-in class required by the task to be executed to obtain the plug-in corresponding to the task to be executed.
Step S216, controlling the scheduler to control the plug-in through the interface to execute the task to be executed.
During specific implementation, because the scheduler class loader and the plug-in class loader belong to the same class loader, and the plug-in classes loaded by the plug-in class loader are invisible to the scheduler, but because the scheduler class loader and the plug-in class loader share the same upper interface class loader, and the classes loaded by the upper level loader are visible to the lower level class loader, the scheduler class loader can sense the plug-in classes loaded by the plug-in class loader according to the interface class loader, so that the scheduler can control the plug-in, and can also understand the plug-in obtained after the plug-in class instance loaded by the plug-in class loader, and the plug-in can be returned to the scheduler through the interface obtained by instantiation of the interface class, so that the scheduler can control the plug-in to execute the task to be executed.
In some embodiments, the interface Class loader can adopt an App Class L loader, the Scheduler Class loader adopts a Scheduler Class L loader, and the plug-in Class loader adopts a plug Class L loader, wherein the App Class L loader only allows loading of classes loaded by the Scheduler Class L loader, classes loaded by the plug Class L loader and interface classes, the Scheduler Class L loader is used for loading the Scheduler Class, and the plug Class L loader is used for loading the plug-in Class.
For example, assuming that the plug-in class corresponding to the task to be executed is somejobimpal, after the scheduler class instantiates to obtain the scheduler, the scheduler may instantiate a plug-in class loader entity, then call the plug-in class loading loadplug method to load the plug-in class required by the task to be executed, instantiate the plug-in class to obtain the plug-in, and return the plug-in to the scheduler in the form of an interface, and the scheduler further controls the whole process of the task executed by the plug-in, where the code is as follows:
Figure BDA0002429525810000101
Figure BDA0002429525810000111
class is the scheduler class, which is loaded by the scheduler class loader in the example code above; class is a plug-in class and is loaded by a plug-in class loader; job is an interface class and is loaded by an interface class loader; because the scheduler class and the plug-in class are loaded by different class loaders, the scheduler cannot sense the plug-in class loading, but the interface class of the plug-in class is loaded by the interface class loader, and because the class plug-in class loader loaded by the interface class loader and the scheduler class loader are visible, the plug-in class loaded by the plug-in class loader and the plug-in obtained after instantiation can be returned to the scheduler in the form of an interface.
In a specific implementation, if there are a plurality of tasks to be executed, the step S216 may be implemented by: the scheduler controls the plug-in of each task to be executed through the interface so as to execute each task to be executed.
If there are multiple tasks to be executed, the scheduler may instantiate a class of a plug-in class loader for each task to be executed, to obtain a plug-in class loader corresponding to each task to be executed. Each plug-in class loader needs to load the plug-in class required by the corresponding task, instantiates the plug-in class required by the task to be executed, and obtains the plug-in of the version corresponding to each task to be executed. Because the plug-in corresponding to each task to be executed is only loaded into the corresponding plug-in class loader, each plug-in class loader is independent from each other, and different tasks can be realized based on interfaces, for example, java has a java start-stop mode, shell has a shell start-stop mode, and therefore, the scheduler can obtain the plug-in corresponding to each task to be executed through the interface to execute the task to be executed.
In step S218, if the task to be executed is completed, the plug-in class loader corresponding to the task to be executed is deleted from the memory through the scheduler.
When the tasks to be executed are executed, the scheduler can discard or recycle the plug-in class loader instantiated by the scheduler, namely, the plug-in class loader is deleted from the memory, so that the memory occupation can be reduced, and the plug-in class loader corresponding to each task to be executed can be ensured to be independent.
The task execution method comprises the steps of firstly creating a class loader and a hierarchical relation of the class loader, then loading an interface class through an interface class loader in the class loader, and instantiating and loading the obtained interface class to obtain an interface; further receiving a task to be executed, loading a scheduler class through a scheduler class loader, and instantiating the loaded scheduler class to obtain a scheduler; then instantiating the class of the plug-in class loader for the task to be executed through the scheduler to obtain the plug-in class loader corresponding to the task to be executed; and finally, controlling the scheduler to control the plug-ins through an interface so as to execute the task to be executed. In the invention, the scheduler can control the plug-in to execute the task to be executed through the hierarchical relation of the loader, and in the mode, a new plug-in class loader is instantiated to load the plug-in class when the task to be executed is executed each time, so that the multi-version plug-in can be loaded simultaneously, the personalized requirements of a user on task execution can be met, and the method is also suitable for all task execution scenes.
Corresponding to the embodiment of the task execution method, an embodiment of the present invention further provides a task execution device, as shown in fig. 4, where the task execution device includes:
and the task receiving module 40 is used for receiving the task to be executed.
The loader instantiation module 41 is configured to instantiate a preset class of a plug-in class loader for the task to be executed through a preset scheduler to obtain the plug-in class loader corresponding to the task to be executed; the plug-in class loader is used for loading plug-in classes required by executing tasks to be executed.
And the class loading module 42 is used for loading the plug-in classes required by the task to be executed through the plug-in class loader.
And the task execution module 43 is configured to instantiate a plug-in class required by the task to be executed, obtain a plug-in corresponding to the task to be executed, and control the plug-in through the scheduler to execute the task to be executed.
The task execution device firstly receives a task to be executed; instantiating the class of a preset plug-in class loader for the task to be executed through a preset scheduler to obtain the plug-in class loader corresponding to the task to be executed; the plug-in class loader is used for loading plug-in classes required by executing tasks to be executed; loading the plug-in classes required by the task to be executed through the plug-in class loader; instantiating the plug-in class required by the task to be executed to obtain the plug-in corresponding to the task to be executed, and controlling the plug-in to execute the task to be executed through a scheduler. In the invention, when a plurality of tasks need to be executed simultaneously, a plug-in class is instantiated for each task through a scheduler to be loaded, so that each plug-in class loader loads the plug-in class required by the corresponding task, and the plug-in class is instantiated to obtain the plug-in of the version required by each task, so that the scheduler controls the plug-ins of different versions to execute the tasks simultaneously; according to the method, corresponding plug-in classes are loaded through different plug-in class loaders, so that the problem that the same plug-in class cannot be loaded by one class loader for multiple times at the same time is solved, multiple versions of the same plug-in run in parallel, and the parallel operation requirements of various tasks are met.
Further, the apparatus further includes a loader relationship creating module configured to: creating a class loader and a hierarchical relation of the class loader; this type of loader comprises: the system comprises an interface class loader, a plug-in class loader and a scheduler class loader; in the hierarchical relation, the interface class loader is higher than the plug-in class loader and the scheduler class loader in hierarchy; the plug-in class loader is used for loading preset plug-in classes; the scheduler class loader is used for loading a preset scheduler class; the interface class loader is used for loading a preset interface class; the scheduler obtained after the scheduler class is instantiated controls the plug-in obtained after the plug-in class is instantiated through the interface obtained after the interface class is instantiated.
Specifically, the scheduler is obtained by: loading a preset scheduler class through a scheduler class loader; and instantiating and loading the obtained scheduler class to obtain the scheduler.
Further, the apparatus further includes an interface instantiation module configured to: loading a preset interface class through an interface class loader; instantiating and loading the obtained interface class to obtain an interface; the task execution module 43 is configured to: if the task to be executed comprises a plurality of tasks, the scheduler controls the plug-in of each task to be executed through the interface so as to execute each task to be executed.
Specifically, the apparatus further includes a loader deleting module, configured to: and if the task to be executed is completely executed, deleting the plug-in class loader corresponding to the task to be executed from the memory through the scheduler.
The implementation principle and the technical effect of the task execution device provided by the embodiment of the invention are the same as those of the method embodiment, and for the sake of brief description, no part of the embodiment of the device is mentioned, and reference may be made to the corresponding contents in the method embodiment.
An embodiment of the present invention further provides a server, as shown in fig. 5, where the server includes a processor 101 and a memory 100, where the memory 100 stores machine executable instructions capable of being executed by the processor 101, and the processor executes the machine executable instructions to implement the above task execution method.
Further, the server shown in fig. 5 further includes a bus 102 and a communication interface 103, and the processor 101, the communication interface 103 and the memory 100 are connected through the bus 102.
The memory 100 may include a high-speed Random Access Memory (RAM) and may further include a non-volatile memory (non-volatile memory), such as at least one disk memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like can be used. The bus 102 may be an ISA bus, PCI bus, EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 5, but this does not indicate only one bus or one type of bus.
The processor 101 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 101. The processor 101 may be a general-purpose processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 100, and the processor 101 reads the information in the memory 100, and completes the steps of the method of the foregoing embodiment in combination with the hardware thereof.
Embodiments of the present invention further provide a machine-readable storage medium, where the machine-readable storage medium stores machine-executable instructions, and when the machine-executable instructions are called and executed by a processor, the machine-executable instructions cause the processor to implement an execution method of the tasks.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the apparatus and/or the electronic device described above may refer to corresponding processes in the foregoing method embodiments, and are not described herein again.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present invention, which are used for illustrating the technical solutions of the present invention and not for limiting the same, and the protection scope of the present invention is not limited thereto, although the present invention is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (11)

1. A method for performing a task, the method comprising:
receiving a task to be executed;
instantiating a preset plug-in class loader class for the task to be executed through a preset scheduler to obtain a plug-in class loader corresponding to the task to be executed; the plug-in class loader is used for loading plug-in classes required by executing the task to be executed;
loading the plug-in classes required by the task to be executed through the plug-in class loader;
and instantiating the plug-in class required by the task to be executed to obtain the plug-in corresponding to the task to be executed, and controlling the plug-in through the scheduler to execute the task to be executed.
2. The method of claim 1, wherein prior to the step of receiving a task to be performed, the method further comprises:
creating a class loader and a hierarchical relationship of the class loader; the class loader comprises: the system comprises an interface class loader, a plug-in class loader and a scheduler class loader; in the hierarchical relationship, the interface class loader is hierarchically higher than the plug-in class loader and the scheduler class loader;
the plug-in class loader is used for loading a preset plug-in class; the scheduler class loader is used for loading a preset scheduler class; the interface class loader is used for loading a preset interface class; and the scheduler obtained after the scheduler class is instantiated controls the plug-in obtained after the plug-in class is instantiated through the interface obtained after the interface class is instantiated.
3. The method of claim 2, wherein the scheduler is obtained by:
loading a preset scheduler class through the scheduler class loader;
and instantiating and loading the obtained scheduler class to obtain the scheduler.
4. The method of claim 2, wherein prior to the step of receiving the task to be performed, the method further comprises: loading a preset interface class through the interface class loader; instantiating and loading the obtained interface class to obtain an interface;
the step of controlling the plug-in by the scheduler includes: if the tasks to be executed comprise a plurality of tasks, the scheduler controls the plug-in of each task to be executed through the interface so as to execute each task to be executed.
5. The method of claim 1, further comprising:
and if the task to be executed is completely executed, deleting the plug-in class loader corresponding to the task to be executed from the memory through the scheduler.
6. An apparatus for performing a task, the apparatus comprising:
the task receiving module is used for receiving a task to be executed;
the loader instantiation module is used for instantiating a preset plug-in class loader class for the task to be executed through a preset scheduler to obtain a plug-in class loader corresponding to the task to be executed; the plug-in class loader is used for loading plug-in classes required by executing the task to be executed;
the class loading module is used for loading the plug-in classes required by the task to be executed through the plug-in class loader;
and the task execution module is used for instantiating the plug-in class required by the task to be executed to obtain the plug-in corresponding to the task to be executed, and controlling the plug-in through the scheduler to execute the task to be executed.
7. The apparatus of claim 6, further comprising a loader relationship creation module to:
creating a class loader and a hierarchical relationship of the class loader; the class loader comprises: the system comprises an interface class loader, a plug-in class loader and a scheduler class loader; in the hierarchical relationship, the interface class loader is hierarchically higher than the plug-in class loader and the scheduler class loader;
the plug-in class loader is used for loading a preset plug-in class; the scheduler class loader is used for loading a preset scheduler class; the interface class loader is used for loading a preset interface class; and the scheduler obtained after the scheduler class is instantiated controls the plug-in obtained after the plug-in class is instantiated through the interface obtained after the interface class is instantiated.
8. The apparatus of claim 7, further comprising an interface instantiation module to: loading a preset interface class through the interface class loader; instantiating and loading the obtained interface class to obtain an interface;
the task execution module is configured to: if the tasks to be executed comprise a plurality of tasks, the scheduler controls the plug-in of each task to be executed through the interface so as to execute each task to be executed.
9. The apparatus of claim 6, further comprising a loader deletion module to:
and if the task to be executed is completely executed, deleting the plug-in class loader corresponding to the task to be executed from the memory through the scheduler.
10. A server comprising a processor and a memory, the memory storing machine executable instructions executable by the processor, the processor executing the machine executable instructions to perform a method of performing a task according to any one of claims 1 to 5.
11. A machine-readable storage medium having stored thereon machine-executable instructions which, when invoked and executed by a processor, cause the processor to perform a method of performing a task as claimed in any of claims 1 to 5.
CN202010227852.XA 2020-03-27 2020-03-27 Task execution method, device and server Active CN111443959B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010227852.XA CN111443959B (en) 2020-03-27 2020-03-27 Task execution method, device and server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010227852.XA CN111443959B (en) 2020-03-27 2020-03-27 Task execution method, device and server

Publications (2)

Publication Number Publication Date
CN111443959A true CN111443959A (en) 2020-07-24
CN111443959B CN111443959B (en) 2023-04-25

Family

ID=71649147

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010227852.XA Active CN111443959B (en) 2020-03-27 2020-03-27 Task execution method, device and server

Country Status (1)

Country Link
CN (1) CN111443959B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112068903A (en) * 2020-09-21 2020-12-11 深圳市欢太科技有限公司 Application loading method, application loading device, medium and equipment
CN112445543A (en) * 2020-11-26 2021-03-05 杭州趣链科技有限公司 Class calling method and device of intelligent contract and electronic equipment
CN116594717A (en) * 2023-05-24 2023-08-15 上海汉朔信息科技有限公司 Class loading isolation method, device, equipment and medium

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102043645A (en) * 2009-10-20 2011-05-04 阿里巴巴集团控股有限公司 Plug-in loading method and device
US20140040874A1 (en) * 2012-07-31 2014-02-06 Kevin Lee Wilson Implementing multiple versions of a plug-in concurrently
CN104166590A (en) * 2013-05-20 2014-11-26 阿里巴巴集团控股有限公司 Task scheduling method and system
CN104699537A (en) * 2015-03-18 2015-06-10 北京奇虎科技有限公司 Program control method, activity module scheduling method and corresponding devices thereof
CN106909406A (en) * 2015-12-23 2017-06-30 北京奇虎科技有限公司 A kind of method and device of the APK plug-in units of loading application programs
CN107463391A (en) * 2016-06-03 2017-12-12 阿里巴巴集团控股有限公司 Task processing method, device and equipment
CN108491236A (en) * 2018-03-23 2018-09-04 努比亚技术有限公司 A kind of plug-in loading method, device and computer readable storage medium
CN109462507A (en) * 2018-11-15 2019-03-12 北京金山云网络技术有限公司 Configure update method, device, system and electronic equipment
CN109614167A (en) * 2018-12-07 2019-04-12 杭州数澜科技有限公司 A kind of method and system managing plug-in unit
CN110221878A (en) * 2019-06-17 2019-09-10 北京金山安全软件有限公司 Game service updating method and device, electronic equipment and storage medium
CN110308945A (en) * 2019-05-22 2019-10-08 百度在线网络技术(北京)有限公司 The dynamic loading method and device of plug-in unit

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102043645A (en) * 2009-10-20 2011-05-04 阿里巴巴集团控股有限公司 Plug-in loading method and device
US20140040874A1 (en) * 2012-07-31 2014-02-06 Kevin Lee Wilson Implementing multiple versions of a plug-in concurrently
CN104166590A (en) * 2013-05-20 2014-11-26 阿里巴巴集团控股有限公司 Task scheduling method and system
CN104699537A (en) * 2015-03-18 2015-06-10 北京奇虎科技有限公司 Program control method, activity module scheduling method and corresponding devices thereof
CN106909406A (en) * 2015-12-23 2017-06-30 北京奇虎科技有限公司 A kind of method and device of the APK plug-in units of loading application programs
CN107463391A (en) * 2016-06-03 2017-12-12 阿里巴巴集团控股有限公司 Task processing method, device and equipment
CN108491236A (en) * 2018-03-23 2018-09-04 努比亚技术有限公司 A kind of plug-in loading method, device and computer readable storage medium
CN109462507A (en) * 2018-11-15 2019-03-12 北京金山云网络技术有限公司 Configure update method, device, system and electronic equipment
CN109614167A (en) * 2018-12-07 2019-04-12 杭州数澜科技有限公司 A kind of method and system managing plug-in unit
CN110308945A (en) * 2019-05-22 2019-10-08 百度在线网络技术(北京)有限公司 The dynamic loading method and device of plug-in unit
CN110221878A (en) * 2019-06-17 2019-09-10 北京金山安全软件有限公司 Game service updating method and device, electronic equipment and storage medium

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112068903A (en) * 2020-09-21 2020-12-11 深圳市欢太科技有限公司 Application loading method, application loading device, medium and equipment
CN112068903B (en) * 2020-09-21 2024-05-03 深圳市欢太科技有限公司 Application program loading method, application program loading device, medium and equipment
CN112445543A (en) * 2020-11-26 2021-03-05 杭州趣链科技有限公司 Class calling method and device of intelligent contract and electronic equipment
CN116594717A (en) * 2023-05-24 2023-08-15 上海汉朔信息科技有限公司 Class loading isolation method, device, equipment and medium
CN116594717B (en) * 2023-05-24 2024-03-08 上海汉朔信息科技有限公司 Class loading isolation method, device, equipment and medium

Also Published As

Publication number Publication date
CN111443959B (en) 2023-04-25

Similar Documents

Publication Publication Date Title
CN111443959A (en) Task execution method and device and server
CN107896162B (en) Deployment method and device of monitoring system, computer equipment and storage medium
CN113377348A (en) Task adjustment method applied to task engine, related device and storage medium
CN112272218B (en) Cloud platform instance resource operation method and device, computer equipment and storage medium
CN105740033A (en) Terminal equipment, plug-in loading and running device and plug-in loading and running method
CN112765023A (en) Test case generation method and device
CN114531477B (en) Method and device for configuring functional components, computer equipment and storage medium
CN110162344B (en) Isolation current limiting method and device, computer equipment and readable storage medium
CN113190282A (en) Android operating environment construction method and device
CN111736884A (en) Componentization method and system
CN111309303B (en) Code generation method and device, computer equipment and storage medium
CN111124382A (en) Attribute assignment method and device in Java and server
CN112256249A (en) Method and equipment for expanding Android system function and computer storage medium
CN113126982B (en) Application program generation and operation method and device
EP4191444A1 (en) Image configuration method, device and system, and storage medium
CN112764729A (en) Application software development method and device, computer equipment and readable storage medium
CN112596780A (en) Service execution method and device
US11017032B1 (en) Document recovery utilizing serialized data
CN111459570B (en) PDF plug-in loading method, electronic equipment and computer storage medium
CN108664293B (en) Application control method and device in android system
CN114546457A (en) Plug-in implementation method for multi-version application, electronic equipment and storage medium
CN111399994A (en) Request scheduling method and device, electronic equipment and storage medium
CN112579126A (en) Software development platform and software development method
CN111880922A (en) Processing method, device and equipment for concurrent tasks
CN116382751A (en) Method, device, equipment, system and storage medium for updating application applet

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
GR01 Patent grant
GR01 Patent grant