CN112463331B - Task scheduling optimization implementation method based on JAVA single thread pool - Google Patents

Task scheduling optimization implementation method based on JAVA single thread pool Download PDF

Info

Publication number
CN112463331B
CN112463331B CN202011386766.XA CN202011386766A CN112463331B CN 112463331 B CN112463331 B CN 112463331B CN 202011386766 A CN202011386766 A CN 202011386766A CN 112463331 B CN112463331 B CN 112463331B
Authority
CN
China
Prior art keywords
task
thread pool
processing
equipment
tasks
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.)
Active
Application number
CN202011386766.XA
Other languages
Chinese (zh)
Other versions
CN112463331A (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.)
Tianjin Optical Electrical Communication Technology Co Ltd
Original Assignee
Tianjin Optical Electrical Communication 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 Tianjin Optical Electrical Communication Technology Co Ltd filed Critical Tianjin Optical Electrical Communication Technology Co Ltd
Priority to CN202011386766.XA priority Critical patent/CN112463331B/en
Publication of CN112463331A publication Critical patent/CN112463331A/en
Application granted granted Critical
Publication of CN112463331B publication Critical patent/CN112463331B/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/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
    • 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
    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5011Pool
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Multi Processors (AREA)

Abstract

The invention discloses a task scheduling optimization implementation method based on a JAVA single thread pool. The method realizes the scheduling optimization of tasks by using a single-thread pool technology in java language. Firstly, a certain number of single thread pools are newly established, each single thread pool is used for processing tasks of different equipment, and the task scheduling mode is realized according to the single thread pool task processing class, the task distribution control class and the task distribution control class. The method utilizes the self-contained queue in the single thread pool to realize the serial processing of the tasks in the same thread pool, and realizes the task scheduling at the upper level of the single thread pool, thereby improving the efficiency and saving the resources.

Description

Task scheduling optimization implementation method based on JAVA single thread pool
Technical Field
The invention relates to the field of equipment control application software, in particular to a task scheduling optimization implementation method based on a JAVA single thread pool. The scheduling optimization of tasks is realized by using a single thread pool technology in java language.
Background
With the development of communication and computer technologies, a plurality of device control software systems have more and more requirements on concurrent execution of tasks, and meanwhile, the realization of serialization between tasks of the same device is required, the most methods are used for using queues in time at present, subtasks in different tasks are put into different queues, but if too many devices controlled by the software system are accessed, a plurality of device task processing queues need to be created, and the tasks still need to be taken out from the device queues and added into a thread pool to execute the tasks when instructions are processed, but because the number of CPU cores of the system is fixed, the efficiency cannot be improved, and serious waste of system resources is caused. When the queue is used, the task serial of the same equipment cannot be well controlled, the tasks of different equipment are parallel, and sometimes, the task execution sequence of the same equipment is wrong, so that the equipment runs problematically.
Disclosure of Invention
In view of the problems in the prior art, the invention provides a task scheduling optimization implementation method based on a JAVA single thread pool. Aiming at the situation that a scene is a multi-device task, the method requires to realize the serial of the same device task, the parallel of different device tasks as much as possible to improve the efficiency and save the system resources as much as possible. The method is based on task scheduling of a newSingleThreadExecutor single-thread pool in Java language, realizes serial processing of tasks in the same thread pool by utilizing a self-contained queue in the single-thread pool, and realizes task scheduling at the upper level of the single-thread pool, thereby improving efficiency and saving resources.
The technical scheme adopted by the invention is as follows: a task scheduling optimization implementation method based on a JAVA single thread pool is characterized in that a certain number of single thread pools are newly built, each single thread pool is used for processing tasks of different devices, and the method is implemented by a task scheduling mode of the single thread pools according to the following three types:
class of single-threaded pool task processing
The single thread pool task processing class comprises a newSingleThreadExecutor single thread pool and a MAP; the single thread pool is used for processing the equipment thread task, and the buffer memory of the equipment task is realized by utilizing a self-contained queue in the newSingleThreadExecutor; the MAP is used for storing the serial numbers of all unprocessed tasks of the equipment, the key of the MAP is the equipment serial number, and the value is the equipment task serial number.
Task distribution control class
The task distribution control class comprises a constant value and two MAPs; the constant value is used for identifying the number of instantiated single-thread pool task processing classes, the first MAP is used for storing the instantiated single-thread pool task processing classes and the single-thread pool task processing classes in use by the equipment, keys of the MAP are single-thread pool task processing class numbers or equipment numbers, and the values are the instantiated single-thread pool task processing classes; the second MAP is used for recording equipment tasks, keys of the MAP are single thread pool task processing class numbers, and values are equipment numbers contained in the single thread pool task processing class; the task distribution control class instantiates N single-thread pool task processing classes in a circulating mode, and stores the single-thread pool task processing class number and the single-thread pool task processing class in a first MAP; the task distribution control class is responsible for distributing tasks and receiving equipment tasks, and distributes the equipment tasks to different single thread pool task processing classes; the specific distribution method comprises the following steps:
(1) and when the instantiated single thread pool task processing class is not completely occupied by the device tasks, sequentially distributing the device tasks into different single thread pool task processing classes.
(2) And when all the single-thread pool task processing classes are occupied, calculating which single-thread pool task processing class processes less equipment according to the equipment tasks recorded in the second MAP, and distributing the equipment tasks into which single-thread pool task processing class.
Class of processing thread task of equipment
And the device thread task processing class is responsible for processing the device tasks, and removes the task numbers stored in the MAP in the single thread pool task processing class after the device tasks are realized, and if the task numbers of the same devices in the MAP in the single thread pool task processing class are removed, the data of the related device numbers in the two MAPs in the task distribution control class are all cleared, so that the resource release is realized.
In step two, the receiving device task and the task distribution process execute the following operations: after receiving the device task, firstly judging whether the device task is a processable device task, and if not, processing according to an exception; if yes, entering an operation task queue, extracting task queue data, then judging whether the same numbered task exists according to the equipment number, and if yes, distributing the task to a specified single thread pool queue and recording; if the single-thread pool queue does not exist, distributing the tasks to the single-thread pool queue with the least tasks of the current processing equipment and recording the single-thread pool queue; and returning to continue extracting the task queue data.
In the third step of the invention, the task flow of the processing equipment executes the following operations: firstly, judging whether a thread task exists or not, and waiting if the thread task does not exist; if the thread task is processed, whether the processing is finished or not is judged, and if the processing is not finished, the processing is continued; if the processing is finished, removing the stored equipment task numbers, then judging whether the same equipment task numbers are all removed, and if the same equipment task numbers are all removed, clearing the equipment number data; if not, processing continues.
The beneficial effects produced by the invention are as follows: the Java single-thread pool technology is utilized to realize the parallel of different equipment tasks, and the serial execution of the same equipment task in the newSingleThreadExecutor single-thread pool.
Drawings
FIG. 1 is a flow chart of the task and task distribution of a receiving device of the present invention;
FIG. 2 is a flow chart of the task flow of the processing device of the present invention.
Detailed Description
The invention is further described below with reference to the accompanying drawings.
Based on the task scheduling optimization method of the newSingleThreadExecutor single thread pool in the Java language, the task serial processing in the same thread pool is realized by utilizing the self-contained queue in the single thread pool, and the task scheduling is realized at the upper level of the single thread pool. The scheduling mode is realized by the following three classes: a single thread pool task processing class, a task distribution control class, and a device thread task processing class.
Establishing a single-thread pool task processing class, wherein the single-thread pool task processing class comprises a newSingleThreadExecutor single-thread pool and a MAP with the name of squeEndmap; two methods are established in the class, one method is used for submitting the thread tasks in the single thread pool from and to, and the other method is used for recording the task numbers of the thread tasks submitted in the single thread pool in the MAP from and to.
Establishing a task distribution control class, establishing a constant value in the task distribution control class, wherein the constant value is used for identifying the number N of instantiated single-thread pool task processing classes, and establishing an MAP (MAP) with the name of queenMap; a MAP, named devMap, is created that is used to tag device tasks. The initialization method is established to instantiate N single-thread pool task processing classes in a circulating mode and store the single-thread pool task processing class numbers and the single-thread pool task processing classes into the squepmap. The establishment method is used for receiving the equipment tasks, the equipment tasks are distributed into different single thread pool task processing classes, and the specific distribution method comprises the following steps: when the instantiated single-thread pool task processing classes are not completely occupied by the device tasks, the device tasks are sequentially distributed into different single-thread pool task processing classes, and when all the single-thread pool task processing classes are occupied, the number of devices processed by the single-thread pool task processing classes is calculated according to the record in the second MAP, and then the tasks are distributed into the single-thread pool task processing classes. The parameters introduced by the method are instantiated thread task processing classes.
As shown in fig. 1, the receiving device task and task distribution flow performs the following operations: after receiving the device task, firstly judging whether the device task is a processable device task, and if not, processing according to an exception; if yes, entering an operation task queue, extracting task queue data, then judging whether the same numbered task exists according to the equipment number, and if yes, distributing the task to a specified single thread pool queue and recording; if the single-thread pool queue does not exist, distributing the tasks to the single-thread pool queue with the least tasks of the current processing equipment and recording the single-thread pool queue; and returning to continue extracting the task queue data.
And thirdly, establishing a thread task processing class, wherein the thread task processing class inherits the Runnable interface and is used for processing specific equipment tasks. And the establishing method is used for removing the task number stored in the squemap in the single thread pool task processing class after the execution of the device task is finished, and clearing all data related to the device number in the quemap and the devMap in the task distribution control class to realize resource release if the task number of the same device in the squemap is removed.
As shown in fig. 2, the processing device task flow performs the following operations: firstly, judging whether a thread task exists or not, and waiting if the thread task does not exist; if the thread task is processed, whether the processing is finished or not is judged, and if the processing is not finished, the processing is continued; if the processing is finished, removing the stored equipment task numbers, then judging whether the same equipment task numbers are all removed, and if the same equipment task numbers are all removed, clearing the equipment number data; if not, processing continues.
When an equipment task arrives, a thread task processing class is instantiated, and a task distribution method in a task distribution control class is called, so that the distribution and execution of the equipment task can be realized.
The method uses the single thread pool in java to replace a queue function, and realizes the functions of distributing, storing, processing and the like of tasks. Aiming at the situation that a scene is a multi-device task, the serial operation of the same device task is required to be realized, different device tasks are parallel as much as possible to improve the efficiency, and the system resources are required to be saved as much as possible. Firstly, a certain number of single thread pools are newly built, each single thread pool can be used for processing tasks of different devices, the tasks of the different devices are circularly added into a thread pool, before the thread pool is not completely occupied, the tasks without the devices are distributed into the different single thread pools, the thread pool where the device task is located is marked, and then the issued device tasks are all added into the thread pool. When the thread pool is fully occupied, the tasks are distributed to the thread pool with the least processing equipment number according to the task distribution principle, and after the execution of a certain equipment task in the thread pool is completed, the mark between the equipment task and the thread pool is cancelled, so that the thread pool resources are released, and the purposes of saving resources and improving efficiency are achieved.

Claims (3)

1. A task scheduling optimization implementation method based on a JAVA single thread pool is characterized in that a certain number of single thread pools are newly built, each single thread pool is used for processing tasks of different devices, and the method is implemented by a task scheduling mode of the single thread pools according to the following three types:
class of single-threaded pool task processing
The single thread pool task processing class comprises a newSingleThreadExecutor single thread pool and a MAP; the single thread pool is used for processing the equipment thread task, and the buffer memory of the equipment task is realized by utilizing a self-contained queue in the newSingleThreadExecutor; the MAP is used for storing the serial numbers of all unprocessed tasks of the equipment, the key of the MAP is the equipment serial number, and the value is the equipment task serial number;
task distribution control class
The task distribution control class comprises a constant value and two MAPs; the constant value is used for identifying the number of instantiated single-thread pool task processing classes, the first MAP is used for storing the instantiated single-thread pool task processing classes and the single-thread pool task processing classes in use by the equipment, keys of the MAP are single-thread pool task processing class numbers or equipment numbers, and the values are the instantiated single-thread pool task processing classes; the second MAP is used for recording equipment tasks, keys of the MAP are single thread pool task processing class numbers, and values are equipment numbers contained in the single thread pool task processing class; the task distribution control class instantiates N single-thread pool task processing classes in a circulating mode, and stores the single-thread pool task processing class number and the single-thread pool task processing class in a first MAP; the task distribution control class is responsible for distributing tasks and receiving equipment tasks, and distributes the equipment tasks to different single thread pool task processing classes; the specific distribution method comprises the following steps:
when the instantiated single thread pool task processing classes are not completely occupied by the equipment tasks, the equipment tasks are sequentially distributed into different single thread pool task processing classes;
when all the single-thread pool task processing classes are occupied, calculating which single-thread pool task processing class processes less equipment according to the equipment tasks recorded in the second MAP, and distributing the equipment tasks into which single-thread pool task processing class;
class of processing thread task of equipment
And the device thread task processing class is responsible for processing the device tasks, and removes the task numbers stored in the MAP in the single thread pool task processing class after the device tasks are realized, and if the task numbers of the same devices in the MAP in the single thread pool task processing class are removed, the data of the related device numbers in the two MAPs in the task distribution control class are all cleared, so that the resource release is realized.
2. The method according to claim 1, wherein in step two, the receiving device task and the task distribution process perform the following operations: after receiving the device task, firstly judging whether the device task is a processable device task, and if not, processing according to an exception; if yes, entering an operation task queue, extracting task queue data, then judging whether the same numbered task exists according to the equipment number, and if yes, distributing the task to a specified single thread pool queue and recording; if the single-thread pool queue does not exist, distributing the tasks to the single-thread pool queue with the least tasks of the current processing equipment and recording the single-thread pool queue; and returning to continue extracting the task queue data.
3. The method according to claim 1, wherein in step three, the task flow of the processing device performs the following operations: firstly, judging whether a thread task exists or not, and waiting if the thread task does not exist; if the thread task is processed, whether the processing is finished or not is judged, and if the processing is not finished, the processing is continued; if the processing is finished, removing the stored equipment task numbers, then judging whether the same equipment task numbers are all removed, and if the same equipment task numbers are all removed, clearing the equipment number data; if not, processing continues.
CN202011386766.XA 2020-12-02 2020-12-02 Task scheduling optimization implementation method based on JAVA single thread pool Active CN112463331B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011386766.XA CN112463331B (en) 2020-12-02 2020-12-02 Task scheduling optimization implementation method based on JAVA single thread pool

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011386766.XA CN112463331B (en) 2020-12-02 2020-12-02 Task scheduling optimization implementation method based on JAVA single thread pool

Publications (2)

Publication Number Publication Date
CN112463331A CN112463331A (en) 2021-03-09
CN112463331B true CN112463331B (en) 2022-04-15

Family

ID=74805506

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011386766.XA Active CN112463331B (en) 2020-12-02 2020-12-02 Task scheduling optimization implementation method based on JAVA single thread pool

Country Status (1)

Country Link
CN (1) CN112463331B (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2014006573A (en) * 2012-06-21 2014-01-16 Fujitsu Ltd Monitoring control system including task execution order control function
CN103605576A (en) * 2013-11-25 2014-02-26 华中科技大学 Multithreading-based MapReduce execution system
CN104754052A (en) * 2015-04-01 2015-07-01 贵州电网公司信息通信分公司 Message pushing method based on Websocket
CN106502773A (en) * 2016-10-09 2017-03-15 武汉斗鱼网络科技有限公司 There is data asynchronous processing method and the module of synchronous callback information function
CN106802826A (en) * 2016-12-23 2017-06-06 中国银联股份有限公司 A kind of method for processing business and device based on thread pool
CN109308293A (en) * 2018-12-07 2019-02-05 广东中鹏热能科技有限公司 Table method is divided in point library in big concurrent data library
CN110609707A (en) * 2018-06-14 2019-12-24 北京嘀嘀无限科技发展有限公司 Online data processing system generation method, device and equipment
CN111198689A (en) * 2019-12-30 2020-05-26 北京明略软件系统有限公司 Code execution method and device and computer readable storage medium
CN111367645A (en) * 2020-03-18 2020-07-03 中国建设银行股份有限公司 Real-time task scheduling control method, system, equipment and readable storage medium
CN111984402A (en) * 2020-07-25 2020-11-24 苏州浪潮智能科技有限公司 Unified scheduling monitoring method and system for thread pool

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2014006573A (en) * 2012-06-21 2014-01-16 Fujitsu Ltd Monitoring control system including task execution order control function
CN103605576A (en) * 2013-11-25 2014-02-26 华中科技大学 Multithreading-based MapReduce execution system
CN104754052A (en) * 2015-04-01 2015-07-01 贵州电网公司信息通信分公司 Message pushing method based on Websocket
CN106502773A (en) * 2016-10-09 2017-03-15 武汉斗鱼网络科技有限公司 There is data asynchronous processing method and the module of synchronous callback information function
CN106802826A (en) * 2016-12-23 2017-06-06 中国银联股份有限公司 A kind of method for processing business and device based on thread pool
CN110609707A (en) * 2018-06-14 2019-12-24 北京嘀嘀无限科技发展有限公司 Online data processing system generation method, device and equipment
CN109308293A (en) * 2018-12-07 2019-02-05 广东中鹏热能科技有限公司 Table method is divided in point library in big concurrent data library
CN111198689A (en) * 2019-12-30 2020-05-26 北京明略软件系统有限公司 Code execution method and device and computer readable storage medium
CN111367645A (en) * 2020-03-18 2020-07-03 中国建设银行股份有限公司 Real-time task scheduling control method, system, equipment and readable storage medium
CN111984402A (en) * 2020-07-25 2020-11-24 苏州浪潮智能科技有限公司 Unified scheduling monitoring method and system for thread pool

Also Published As

Publication number Publication date
CN112463331A (en) 2021-03-09

Similar Documents

Publication Publication Date Title
CN106802826B (en) Service processing method and device based on thread pool
US10877766B2 (en) Embedded scheduling of hardware resources for hardware acceleration
US9880875B2 (en) Apparatus and method for hardware-based task scheduling
CN100530111C (en) Multi-thread access indirect register scheduling method
JP2008507015A5 (en)
CN102096603A (en) Task decomposition control method in MapReduce system and scheduling node equipment
CN111400016B (en) Method and equipment for calling application program interface function
CN105550029A (en) Process scheduling method and device
CN107943592B (en) GPU cluster environment-oriented method for avoiding GPU resource contention
CN102455932B (en) Serial execution method, device and system for task instances
CN112463331B (en) Task scheduling optimization implementation method based on JAVA single thread pool
US20130117757A1 (en) Method and apparatus for scheduling application programs
CN113051049A (en) Task scheduling system, method, electronic device and readable storage medium
CN101075219B (en) Method and system for processing interruption
CN116069480B (en) Processor and computing device
CN101349975B (en) Method for implementing interrupt bottom semi-section mechanism in embedded operation system
CN114896295B (en) Data desensitization method, desensitization device and desensitization system in big data scene
US10656967B1 (en) Actor and thread message dispatching
CN107544840A (en) A kind of process management method and device
CN115495249A (en) Task execution method of cloud cluster
CN101976206A (en) Interrupt handling method and device
CN112835692B (en) Log message driven task method, system, storage medium and equipment
CN115114022A (en) Method, system, device and medium for using GPU resources
CN114911538A (en) Starting method of running system and computing equipment
CN109669780B (en) Video analysis method and system

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