Multi-threaded Permission Task Execution Method, System, Electronic Device and Medium
Through the permission task execution method of multi-thread management, the number of task threads is dynamically controlled, and the efficiency and stability problems of security devices when executing permission tasks are solved, achieving efficient and reliable permission task downloads.
Patent Information
- Application Number
- CN202211058823.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-30
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2042-08-30
AI Technical Summary
When executing permission tasks, existing security equipment has the problem of crashes or inefficient execution due to limited data processing capabilities, especially when it is not efficient during parallel execution, and cannot meet the efficiency requirements of the security system.
The multi-threaded permission task execution method is adopted. By generating task threads such as scanning subthreads, logging out subthreads and downloading subthreads, the number of threads is dynamically controlled to ensure that the non-empty queue of the task queue is scanned and the permission tasks are executed, avoiding device crashes caused by insufficient computing power, and improving task processing efficiency.
It improves the execution efficiency and reliability of permission tasks, avoids device crashes caused by insufficient computing power, and reduces the performance overhead of redundant threads through task management optimization, and achieves stable permission task downloads.
Smart Images

Figure CN115421938B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of security devices, and in particular, to a multi-threaded-based permission task execution method, system, electronic device, and medium. Background Art
[0002] With the continuous strengthening of people's security awareness, the security system is also constantly evolving. After the security system is built and put into use, it is necessary to download the permission data of the security system users (such as identity information, access time period, management permissions, etc.) to the security devices, or delete the permission data from the security devices, so that the security system users can control each security device in the security system through the stored permission tasks. If the number of security devices and users is small, the permission data of the users is usually directly input or deleted on each security device, or the permission tasks are stored through an electronic device such as a computer, and the corresponding permission tasks are executed on each security device by using a preset program.
[0003] Although the permission task is a function with a relatively low usage frequency, in the security system and the security industry, there are relatively high requirements for the execution efficiency and execution stability of the permission task. Although the security device provides a device management SDK for developers, and the permission task can be requested to be executed through the preset program by using the device management SDK, if the permission tasks are executed in parallel through the preset program, the security system may crash due to limited data processing capabilities. If the permission tasks of each security device are executed serially, the execution efficiency will be low, which cannot meet the efficiency requirements of the security system. Summary of the Invention
[0004] To provide a basic understanding of some aspects of the disclosed embodiments, a simple summary is given below. The summary is not a comprehensive review, nor is it intended to identify key / important elements or delineate the scope of protection of these embodiments. Instead, it serves as a preamble to the subsequent detailed description.
[0005] In view of the above-mentioned disadvantages of the prior art, the present invention discloses a multi-threaded-based permission task execution method, system, electronic device, and medium to improve the efficiency of the access control device in executing permission tasks.
[0006] The present invention discloses a method for executing permission tasks based on multi-threading, including: obtaining a task queue corresponding to at least one requesting device, where the task queue is used to store the permission tasks of the requesting device. Among them, the task queue storing at least one permission task is determined as a non-empty queue, and the number of non-empty queues in the task queue is determined as the non-empty queue number; generating at least one task thread, and in response to the number of the task threads being less than the non-empty queue number, generating a new task thread. Among them, the task thread includes a scanning sub-thread, a cancellation sub-thread, and a download sub-thread; the scanning sub-thread is used to scan each of the task queues, and in response to not scanning a non-empty queue, re-scan each of the task queues; the cancellation sub-thread is used to count the scanning times of the scanning sub-thread. If the scanning times are greater than or equal to a preset number threshold, cancel the task thread; the download sub-thread is used to, if the scanning sub-thread scans a non-empty queue, clear the scanning times, retrieve permission tasks from the scanned non-empty queue, and execute the retrieved permission tasks.
[0007] In an embodiment of the present invention, after obtaining the task queue corresponding to at least one requesting device, the method further includes: generating a request scheduling thread, where the request scheduling thread includes a receiving sub-thread, a determining sub-thread, a calculating sub-thread, a first adding sub-thread, and a second adding sub-thread; the receiving sub-thread is used to receive a device permission request sent by a client and a device identifier corresponding to the device permission request. Among them, the device permission request includes at least one request task; the determining sub-thread is used to determine a target device corresponding to the device permission request from the requesting devices according to the device identifier, and determine the task queue corresponding to each of the target devices as a target queue; the calculating sub-thread is used to calculate the current task number of the permission tasks in each of the target queues according to a preset queue length threshold to obtain the task free space of each of the target queues; the first adding sub-thread is used to, if the number of request tasks in the device permission request is less than or equal to the task free space of any one of the target queues, add the request tasks as permission tasks to the target queue; the second adding sub-thread is used to, if the number of request tasks in the device permission request is greater than the task free space of any one of the target queues, determine a first task from the request tasks according to the task free space, add the first task as a permission task to the target queue, and add a second task as a dormant task to a preset task storage space. Among them, the second task includes request tasks other than the first task.
[0008] In one embodiment of the present invention, after obtaining a task queue corresponding to at least one requesting device, the method further includes: generating a request receiving thread, where the request receiving thread is used to receive a device permission request sent by a client and a device identifier corresponding to the device permission request, the device permission request includes at least one request task, determining a target device corresponding to the device permission request from the requesting devices according to the device identifier, determining the request task as a sleep task corresponding to the target device, and storing the sleep task in a preset task storage space.
[0009] In one embodiment of the present invention, after generating a request scheduling thread, the method further includes: generating a task wake-up thread, where the task wake-up thread is used to count the current number of permission tasks in each of the task queues every time a preset first time interval elapses. If the current number of permission tasks in any task queue is less than the queue length threshold, select a sleep task corresponding to the task queue from the task storage space, and store the selected sleep task as a new permission task in the task queue.
[0010] In one embodiment of the present invention, in response to the number of task threads being less than the number of non-empty queues in the task queue, generating a new task thread includes: generating a management thread, where the management thread is used to count the number of task threads and the number of non-empty queues in the task queue every time a preset second time interval elapses. If the number of threads meets a first preset condition and a second preset condition, generate a new task thread. If the number of threads does not meet the first preset condition or the second preset condition, reject generating a new task thread, where the first preset condition includes that the number of threads is less than the number of non-empty queues in the task queue, and the second preset condition includes that the number of threads is less than a preset maximum thread threshold.
[0011] In one embodiment of the present invention, the cancellation sub-thread cancels the task thread by the following method: comparing the number of all task threads with a preset minimum thread threshold; if the number of threads is greater than the minimum thread threshold, cancel the task thread where the cancellation sub-thread is located; if the number of threads is less than or equal to the minimum thread threshold, rescan each of the task queues.
[0012] In one embodiment of the present invention, the download sub-thread is further used for: if the scan sub-thread scans a non-empty queue, determining the current state of the non-empty queue as a locked state; after executing the retrieved permission task, determining the current state of the non-empty queue as a scan state; where if the non-empty queue is in the locked state, the non-empty queue cannot be scanned by any task thread.
[0013] The present invention discloses a multi-thread based permission task execution system, comprising: an acquisition module, configured to acquire a task queue corresponding to at least one requesting device, where the task queue is used to store permission tasks of the requesting device, and wherein a task queue storing at least one permission task is determined as a non-empty queue, and the number of non-empty queues in the task queue is determined as the non-empty queue number; a generation module, configured to generate at least one task thread, where the task thread includes a scanning sub-thread, a cancellation sub-thread, and a download sub-thread, the scanning sub-thread is configured to scan each of the task queues, and in response to not scanning a non-empty queue, re-scan each of the task queues, the cancellation sub-thread is configured to count the number of scans of the scanning sub-thread, and if the number of scans is greater than or equal to a preset number threshold, cancel the task thread, the download sub-thread is configured to, if the scanning sub-thread scans a non-empty queue, clear the number of scans, retrieve permission tasks from the scanned non-empty queue, and download the retrieved permission tasks to the corresponding requesting device; a new creation module, configured to generate a new task thread in response to the number of threads of the task thread being less than the number of non-empty queues.
[0014] The present invention discloses an electronic device, comprising: a processor and a memory; the memory is configured to store a computer program, and the processor is configured to execute the computer program stored in the memory so that the electronic device executes the above method.
[0015] The present invention discloses a computer-readable storage medium, on which a computer program is stored: the computer program, when executed by a processor, implements the above method.
[0016] Advantages of the present invention:
[0017] Through the multi-thread based permission task execution method provided by the embodiments of the present disclosure, permission tasks are stored through task queues corresponding to each requesting device, the generated task threads scan each of the task queues, and after scanning a non-empty queue in the task queue, the permission tasks in the non-empty queue are executed. At the same time, if the number of threads is less than the number of non-empty queues, a new task thread is added, and if the number of consecutive scans of the task thread is greater than a preset number threshold, the task thread is cancelled. In this way, the permission tasks are serially downloaded to each requesting device through the task threads. At the same time, conditions are set to dynamically control the number of threads of the task threads, which not only prevents the requesting device from crashing due to insufficient computing power, but also avoids the performance overhead of redundant task threads while ensuring the processing efficiency of the task threads, thereby improving the efficiency of the requesting device in downloading permission tasks and ensuring the reliability of downloading permission tasks.
[0018] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings herein are incorporated into the specification and form a part of this specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application. Obviously, the accompanying drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts. In the drawings:
[0020] Figure 1 is a schematic flowchart of a multi-threaded permission task execution method according to an embodiment of the present invention;
[0021] Figure 2 is a schematic flowchart of another multi-threaded permission task execution method according to an embodiment of the present invention;
[0022] Figure 3 is a schematic structural diagram of a multi-threaded permission task execution system according to an embodiment of the present invention;
[0023] Figure 4 is a schematic structural diagram of another multi-threaded permission task execution system according to an embodiment of the present invention;
[0024] Figure 5 is a schematic structural diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0025] The following uses specific specific examples to illustrate the embodiments of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments. Various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, without conflict, the following embodiments and sub-samples in the embodiments can be combined with each other.
[0026] It should be noted that the illustrations provided in the following embodiments only schematically illustrate the basic concept of the present invention. Therefore, only the components related to the present invention are shown in the drawings, rather than being drawn according to the number, shape, and size of the components in actual implementation. The type, quantity, and ratio of each component in its actual implementation can be arbitrarily changed, and the component layout type may also be more complex.
[0027] In the following description, numerous specific details are set forth to provide a more thorough explanation of embodiments of the present invention. However, it will be apparent to those skilled in the art that embodiments of the present invention may be practiced without these specific details. In other instances, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the present invention.
[0028] In the specification and claims of the embodiments of the present disclosure and the above-mentioned drawings, the terms "first", "second", etc. are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way may be interchanged under appropriate circumstances so as to implement the embodiments of the present disclosure described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion.
[0029] Unless otherwise specified, the term "plurality" means two or more.
[0030] In the embodiments of the present disclosure, the character " / " indicates that the objects before and after are in an "or" relationship. For example, A / B means: A or B.
[0031] The term "and / or" is a description of the association relationship of objects and indicates that three relationships may exist. For example, A and / or B means: A or B, or, the three relationships of A and B.
[0032] In combination Figure 1 As shown, the embodiments of the present disclosure provide a multi-thread-based permission task execution method, including:
[0033] Step S101, obtaining at least one task queue corresponding to a request device, where the task queue is used to store permission tasks of the request device;
[0034] Among them, the task queue storing at least one permission task is determined as a non-empty queue, and the number of non-empty queues in the task queue is determined as the non-empty queue number;
[0035] Step S102, generating at least one task thread;
[0036] Among them, the task thread includes a scanning sub-thread, a cancellation sub-thread, and a download sub-thread;
[0037] Among them, the scanning sub-thread is used to scan each task queue, and in response to not scanning a non-empty queue, re-scan each task queue;
[0038] Among them, the cancellation sub-thread is used to count the number of scans of the scanning sub-thread. If the number of scans is greater than or equal to a preset number threshold, the task thread is cancelled;
[0039] Among them, the download sub-thread is used to clear the scan count if the scan sub-thread scans a non-empty queue, retrieve the permission task from the scanned non-empty queue, and execute the retrieved permission task;
[0040] Step S103, in response to the number of task threads being less than the number of non-empty queues, generate a new task thread.
[0041] Through the method for executing permission tasks based on multi-threading provided by the embodiments of the present disclosure, permission tasks are stored in the task queues corresponding to the respective requesting devices, the generated task threads scan the task queues, and after scanning a non-empty queue in the task queue, execute the permission tasks in the non-empty queue. At the same time, if the number of threads is less than the number of non-empty queues, a new task thread is added, and if the consecutive scan count of the task thread is greater than the preset count threshold, the task thread is cancelled. In this way, the permission tasks are serially downloaded to the respective requesting devices through the task threads. At the same time, the number of task threads is dynamically controlled by setting conditions, which not only avoids the crashing of the requesting device due to insufficient computing power, but also ensures the processing efficiency of the task threads while avoiding the performance overhead of redundant task threads, thereby improving the efficiency of the requesting device for downloading permission tasks and ensuring the reliability of downloading permission tasks.
[0042] Optionally, there is a one-to-one correspondence between the requesting device and the task queue, that is, each requesting device corresponds to only one task queue, and each task queue corresponds to only one requesting device.
[0043] In this way, a task queue is set for each requesting device, and the permission tasks between each requesting device do not interfere with each other, avoiding the chaos of permission tasks between the requesting devices.
[0044] Optionally, the permission tasks in the task queue are arranged in the order from the earliest to the latest according to the task request time, and the task thread retrieves a permission task from the task queue in the order from the earliest to the latest each time and executes the retrieved permission task.
[0045] Optionally, the permission tasks include permission tasks, permission deletion tasks, etc. Among them, the permission task includes downloading permission data to the corresponding requesting device, and the permission deletion task includes deleting the specified permission data from the requesting device.
[0046] Optionally, after obtaining the task queue corresponding to at least one requesting device, the method further includes: generating a request scheduling thread, where the request scheduling thread includes a receiving sub-thread, a determining sub-thread, a calculating sub-thread, a first adding sub-thread, and a second adding sub-thread; the receiving sub-thread is configured to receive a device permission request sent by a client and the device identifier corresponding to the device permission request, where the device permission request includes at least one request task; the determining sub-thread is configured to determine, from the requesting devices, the target device corresponding to the device permission request according to the device identifier, and determine the task queue corresponding to each target device as the target queue; the calculating sub-thread is configured to calculate the current number of tasks of the permission tasks in each target queue according to a preset queue length threshold to obtain the remaining task quantity of each target queue; the first adding sub-thread is configured to, if the number of request tasks in the device permission request is less than or equal to the remaining task quantity of any target queue, add the request tasks as permission tasks to the target queue; the second adding sub-thread is configured to, if the number of request tasks in the device permission request is greater than the remaining task quantity of any target queue, determine a first task from the request tasks according to the remaining task quantity, add the first task as a permission task to the target queue, and add a second task as a dormant task to a preset task storage space, where the second task includes the request tasks other than the first task.
[0047] Optionally, the device identifier is used to represent at least some of the requesting devices.
[0048] In some embodiments, the request scheduling thread receives the request tasks, groups the requesting devices of the request tasks, and maps a bounded task queue. According to the number of tasks that can continue to be accommodated in the task queue, it is determined whether the request tasks stored in the data storage component are to be processed or are being processed. The request tasks being processed are immediately put into the task queue as permission tasks. When the task queue has sufficient capacity, the dormant tasks will be woken up by the thread and continue to be put into the task queue.
[0049] Optionally, after obtaining the task queue corresponding to at least one requesting device, the method further includes: generating a request receiving thread, where the request receiving thread is configured to receive a device permission request sent by a client and the device identifier corresponding to the device permission request, the device permission request includes at least one request task, determine the target device corresponding to the device permission request from the requesting devices according to the device identifier, determine the request tasks as dormant tasks corresponding to the target device, and store the dormant tasks in a preset task storage space.
[0050] Optionally, after generating the request scheduling thread, the method further includes: generating a task wake-up thread, which is used to count the current number of tasks of the permission tasks in each task queue every preset first time interval. If the current number of tasks of the permission tasks in any task queue is less than the queue length threshold, select the dormant tasks corresponding to the task queue from the task storage space, and store the selected dormant tasks as new permission tasks into the task queue.
[0051] In this way, the request scheduling thread automatically allocates the request tasks in the device permission request, adds some of the request tasks as permission tasks to the task queue, puts the remaining request tasks as dormant tasks into the task storage space, and the task wake-up thread adds the corresponding dormant tasks as new permission tasks to the task queue when the task queue has data space, so as to be able to process more device permission requests, and avoid data interruption and data loss caused by program exceptions by improving the throughput, thereby improving the download reliability.
[0052] In some embodiments, the task wake-up thread reloads the tasks that cannot be immediately executed and are stored in the data storage component into the bounded task queue at regular time intervals.
[0053] Optionally, in response to the number of task threads being less than the number of non-empty queues in the task queue, generating a new task thread includes: generating a management thread, which is used to count the number of task threads and the number of non-empty queues in the task queue every preset second time interval. If the number of threads meets the first preset condition and the second preset condition, generate a new task thread. If the number of threads does not meet the first preset condition or the second preset condition, reject generating a new task thread, where the first preset condition includes that the number of threads is less than the number of non-empty queues in the task queue, and the second preset condition includes that the number of threads is less than the preset maximum thread threshold.
[0054] In this way, compared with managing task threads through the thread pool technology, managing permission tasks and task threads through threads such as the request scheduling thread, request receiving thread, task wake-up thread, and management thread realizes the internal management idea of managing threads by threads, has a faster response speed and less configuration content than the thread pool technology, thereby improving the thread efficiency.
[0055] In some embodiments, the role of the management thread is to appropriately increase the number of task threads by comparing the number of queues storing tasks with the number of currently alive task threads in the system.
[0056] Optionally, the cancellation sub-thread cancels the task thread by the following method: comparing the number of threads of all task threads with a preset minimum thread threshold; if the number of threads is greater than the minimum thread threshold, cancel the task thread where the cancellation sub-thread is located; if the number of threads is less than or equal to the minimum thread threshold, rescan each task queue.
[0057] In this way, by satisfying different computing power resource quotas with the minimum thread threshold, the maximum thread threshold, and the queue length threshold, the flexibility of computing power resource allocation is improved, and a balance between download efficiency and download stability is achieved.
[0058] Optionally, the download sub-thread is further used to: if the scan sub-thread scans a non-empty queue, determine the current state of the non-empty queue as the locked state; after executing the retrieved permission task, determine the current state of the non-empty queue as the scan state; wherein, if the non-empty queue is in the locked state, the non-empty queue cannot be scanned by any task thread.
[0059] In some embodiments, after the system is started, the number of initialized threads can be configured and task threads are generated. The role of the task threads is to retrieve tasks from the task queues and execute the tasks; the task threads are not bound to a specific task queue or a specified task thread executes the tasks in a specified task queue. They always run in a loop to traverse all task queues unless the number of threads in the system is greater than the number of core threads, in which case the task threads interrupt themselves and end to maintain the number of threads as the initialized number of threads. Each task thread traverses all task queues in turn. If it checks that there are tasks in a certain task queue, it processes the tasks and locks the task queue so that other task threads cannot process this task queue.
[0060] Combined with Figure 2 As shown in
[0061] Step S201, load all requesting devices and bind a task queue with a queue length threshold to each requesting device;
[0062] Step S202, if the current number of tasks of the permission task in any task queue is less than the queue length threshold, select a new permission task from the task storage space and store it in the task queue;
[0063] Step S203, count the number of non-empty queues Qn in the task queue and count the number of threads Tn of the working threads;
[0064] Step S204, if the number of queues Qn ≥ the number of threads Tn and the maximum thread threshold Tmax > the number of threads Tn, create a new working thread;
[0065] Step S205: Scan each task queue through a worker thread. If the scanning sub-thread scans a non-empty queue, reset the scanning count Mn to zero, retrieve the permission task from the scanned non-empty queue, and execute the retrieved permission task.
[0066] Step S206: In response to not scanning a non-empty queue, re-scan each task queue and count the scanning times Mn of the scanning sub-thread.
[0067] Step S207: If the scanning count Mn ≥ the preset count threshold Mmax and the number of threads Tn > the minimum thread threshold Tmin, log off the task thread.
[0068] Using the multi-thread-based permission task execution method provided by the embodiments of the present disclosure, storing permission tasks through the task queues corresponding to each requesting device, scanning each task queue through the generated task threads, and executing the permission tasks in the non-empty queue after scanning the non-empty queue in the task queue. At the same time, if the number of threads is less than the number of non-empty queues, new task threads are added. If the continuous scanning times of the task threads are greater than the preset count threshold, the task thread is logged off. It has the following advantages:
[0069] First, the permission tasks are serially downloaded to each requesting device through the task threads. At the same time, the number of task threads is dynamically controlled by setting conditions, which not only avoids the crashing of the requesting device due to insufficient computing power, but also ensures the processing efficiency of the task threads while avoiding the performance overhead of redundant task threads, thereby improving the efficiency of the requesting device in downloading permission tasks and ensuring the reliability of downloading permission tasks.
[0070] Second, a task queue is set for each requesting device, and the permission tasks between each requesting device do not interfere with each other, avoiding the chaos of permission tasks between requesting devices.
[0071] Third, the request scheduling thread automatically allocates the request tasks in the device permission request, adds some of the request tasks as permission tasks to the task queue, puts the remaining request tasks as dormant tasks into the task storage space, and the task wake-up thread adds the corresponding dormant tasks as new permission tasks to the task queue when there is data space in the task queue, so as to be able to process more device permission requests, and avoid data interruption and data loss caused by program exceptions by improving the throughput, thereby improving the download reliability.
[0072] Fourth, compared with managing task threads through the thread pool technology, managing permission tasks and task threads through threads such as the request scheduling thread, request receiving thread, task wake-up thread, and management thread realizes the internal management idea of managing threads through threads, with a faster response speed and less configuration content than the thread pool technology, thereby improving the thread efficiency.
[0073] Fifthly, by meeting different computing power resource quotas through the thread minimum threshold, thread maximum threshold, and queue length threshold, the flexibility of computing power resource allocation is improved, and a balance between download efficiency and download stability is achieved.
[0074] Combined with Figure 3 As shown in the figure, an embodiment of the present disclosure provides a multi-threaded permission task execution system, including a device terminal 301, a user terminal 302, and a server terminal 303. Among them, the server terminal 303 includes a task queue 3031, a request scheduling thread 3032, a task wake-up thread 3033, a management thread 3034, a task thread 3035, and a task storage space 3036 corresponding to each device terminal;
[0075] The device terminal 301 is used to store permission data and verify the user through the permission data;
[0076] The user terminal 302 is used to send a device permission request and a device identifier corresponding to the device permission request;
[0077] The task queue 3031 is used to store the permission tasks of the requested device;
[0078] The request scheduling thread 3032 is used to receive the device permission request sent by the client and the device identifier corresponding to the device permission request. Among them, the device permission request includes at least one request task; determine the target device corresponding to the device permission request from the requested devices according to the device identifier, and determine the task queue corresponding to each target device as the target queue; calculate the current task quantity of the permission tasks in each target queue according to the preset queue length threshold to obtain the task free quantity of each target queue; if the number of request tasks in the device permission request is less than or equal to the task free quantity of any target queue, add the request task as a permission task to the target queue; if the number of request tasks in the device permission request is greater than the task free quantity of any target queue, determine the first task from the request tasks according to the task free quantity, add the first task as a permission task to the target queue, and add the second task as a dormant task to the preset task storage space, where the second task includes the request tasks other than the first task;
[0079] The task wake-up thread 3033 is used to count the current task quantity of the permission tasks in each task queue every time a preset first time interval passes. If the current task quantity of the permission tasks in any task queue is less than the queue length threshold, select the dormant task corresponding to the task queue from the task storage space, and deposit the selected dormant task as a new permission task into the task queue;
[0080] The management thread 3034 is used to count the number of task threads and the number of non-empty queues in the task queue every time a preset second time interval elapses. If the number of threads meets the first preset condition and the second preset condition, a new task thread is generated. If the number of threads does not meet the first preset condition or the second preset condition, generating a new task thread is rejected, where the first preset condition includes that the number of threads is less than the number of non-empty queues in the task queue, and the second preset condition includes that the number of threads is less than a preset maximum thread threshold;
[0081] The task thread 3035 is used to scan each task queue, and in response to not scanning a non-empty queue, scan each task queue again; count the number of scans of the scanning sub-thread. If the number of scans is greater than or equal to a preset number threshold, the task thread is cancelled; if the scanning sub-thread scans a non-empty queue, the number of scans is cleared, and the permission task is retrieved from the scanned non-empty queue, and the retrieved permission task is executed.
[0082] Through the multi-thread-based permission task execution system provided by the embodiments of the present disclosure, the permission tasks are stored in the task queues corresponding to the respective requesting devices, the generated task threads are used to scan each task queue, and the permission tasks in the non-empty queue are executed after scanning a non-empty queue in the task queue. At the same time, if the number of threads is less than the number of non-empty queues, a new task thread is added. If the number of consecutive scans of the task thread is greater than a preset number threshold, the task thread is cancelled. In this way, the permission tasks are serially downloaded to each requesting device through the task threads. At the same time, conditions are set to dynamically control the number of threads of the task threads, which not only avoids the crash of the requesting device due to insufficient computing power, but also ensures the processing efficiency of the task threads while avoiding the performance overhead of redundant task threads, thereby improving the efficiency of the requesting device to download permission tasks and ensuring the reliability of downloading permission tasks.
[0083] Combined with Figure 4 As shown, the embodiments of the present disclosure provide a multi-thread-based permission task execution system, including an acquisition module 401, a generation module 402, and a new creation module 403.
[0084] The acquisition module 401 is used to acquire task queues corresponding to at least one requesting device. The task queue is used to store the permission tasks of the requesting device. Among them, the task queue storing at least one permission task is determined as a non-empty queue, and the number of non-empty queues in the task queue is determined as the number of non-empty queues;
[0085] The generation module 402 is used to generate at least one task thread. Among them, the task thread includes a scanning sub-thread, a cancellation sub-thread, and a download sub-thread. The scanning sub-thread is used to scan each task queue, and in response to not scanning a non-empty queue, re-scan each task queue. The cancellation sub-thread is used to count the number of scans of the scanning sub-thread. If the number of scans is greater than or equal to a preset number threshold, the task thread is cancelled. The download sub-thread is used to, if the scanning sub-thread scans a non-empty queue, clear the number of scans, retrieve the permission task from the scanned non-empty queue, and download the retrieved permission task to the corresponding requesting device;
[0086] The new module 403 is used to generate a new task thread in response to the number of threads of the task thread being less than the number of non-empty queues.
[0087] Through the multi-thread-based permission task execution system provided by the embodiments of the present disclosure, the permission tasks are stored in the task queues corresponding to the respective requesting devices, the generated task threads are used to scan each task queue, and the permission tasks in the non-empty queues are executed after a non-empty queue in the task queue is scanned. At the same time, if the number of threads is less than the number of non-empty queues, a new task thread is added, and if the number of consecutive scans of the task thread is greater than the preset number threshold, the task thread is cancelled. In this way, the permission tasks are serially downloaded to the respective requesting devices through the task threads. At the same time, the number of threads of the task threads is dynamically controlled by setting conditions, which not only avoids the crash of the requesting device due to insufficient computing power, but also ensures the processing efficiency of the task threads while avoiding the performance overhead of redundant task threads, thereby improving the efficiency of the requesting device to download the permission tasks and ensuring the reliability of downloading the permission tasks.
[0088] Figure 5 The structural schematic diagram of the computer system of the electronic device suitable for implementing the embodiments of the present application is shown. It should be noted that, Figure 5 The computer system 500 of the shown electronic device is only an example and should not bring any limitations to the functions and usage scopes of the embodiments of the present application.
[0089] Such as Figure 5As shown, computer system 500 includes a Central Processing Unit (CPU) 501, which can perform various appropriate actions and processes according to programs stored in a Read-Only Memory (ROM) 502 or programs loaded from a storage section 508 into a Random Access Memory (RAM) 503, such as executing the methods in the above embodiments. In the RAM 503, various programs and data required for system operations are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An Input / Output (I / O) interface 505 is also connected to the bus 504.
[0090] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including, for example, a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), etc. and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed so that a computer program read from it can be installed into the storage section 508 as needed.
[0091] Specifically, according to an embodiment of the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 509, and / or installed from the removable medium 511. When the computer program is executed by a Central Processing Unit (CPU) 501, various functions defined in the system of the present application are executed.
[0092] It should be noted that the computer-readable medium shown in the embodiments of the present application may be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium may be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable computer program. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium may be transmitted by any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0093] The embodiments of the present disclosure also provide a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements any one of the methods in this embodiment.
[0094] For the computer-readable storage medium in the embodiments of the present disclosure, those of ordinary skill in the art can understand that all or part of the steps for implementing the above method embodiments can be completed by hardware related to a computer program. The foregoing computer program may be stored in a computer-readable storage medium. When the program is executed, it executes the steps including the above method embodiments; and the foregoing storage medium includes: ROM, RAM, magnetic disk, or optical disc and other media that can store program codes.
[0095] The electronic device disclosed in this embodiment includes a processor, a memory, a transceiver, and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and complete communication with each other. The memory is used to store a computer program, the communication interface is used for communication, and the processor and the transceiver are used to run the computer program to enable the electronic device to execute each step of the above method.
[0096] In this embodiment, the memory may include a Random Access Memory (RAM), and may also include a non-volatile memory, such as at least one disk memory.
[0097] The above-mentioned processor may be a general-purpose processor, including a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0098] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure, enabling those skilled in the art to practice them. Other embodiments may include structural, logical, electrical, process, and other changes. The embodiments merely represent possible variations. Unless explicitly required, the individual components and functions are optional, and the order of operations may vary. Parts and sub-samples of some embodiments may be included in or replace parts and sub-samples of other embodiments. Moreover, the terms used in this application are only for describing the embodiments and do not limit the claims. As used in the description of the embodiments and the claims, unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" are intended to also include the plural forms. Similarly, as used in this application, the term "and / or" refers to any and all possible combinations of one or more of the associated listed items. Additionally, when used in this application, the term "comprise" and its variants "comprises" and / or "comprising" etc. mean the presence of the stated sub-samples, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other sub-samples, wholes, steps, operations, elements, components, and / or groupings of these. Without further limitation, an element defined by the statement "comprising one..." does not exclude the presence of additional identical elements in the process, method, or device comprising the element. Herein, each embodiment may focus on the differences from other embodiments, and the same or similar parts among the embodiments may be referred to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method parts disclosed in the embodiments, the relevant parts may refer to the description of the method parts.
[0099] Those skilled in the art will realize that the units and algorithm steps of each example described in connection with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in hardware or software can depend on the specific application and design constraints of the technical solution. The technician can use different methods for each specific application to implement the described functions, but such implementation should not be considered to exceed the scope of the embodiments of the present disclosure. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices, and units described above can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein.
[0100] In the embodiments disclosed herein, the disclosed methods, products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units can be merely a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some sub-samples can be ignored or not executed. Additionally, the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect coupling or communication connection of devices or units can be in electrical, mechanical, or other forms. The units described as separate components can be or can not be physically separated. The components shown as units can be or can not be physical units, that is, they can be located in one place, or can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to implement this embodiment. Additionally, in the embodiments of the present disclosure, the various functional units can be integrated in one processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit.
[0101] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing the specified logical function. In some alternative implementations, the functions marked in the block can occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, which can depend on the functions involved. In the descriptions corresponding to the flowcharts and block diagrams in the accompanying drawings, the operations or steps corresponding to different blocks can also occur in a different order than disclosed in the description. Sometimes, there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, which can depend on the functions involved. Each block in the block diagram and / or flowchart, and the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
Claims
1. A multi-threaded-based permission task execution method, characterized in that, Including: Obtain a task queue corresponding to at least one requesting device, where the task queue is used to store permission tasks of the requesting device. Among them, the task queue storing at least one permission task is determined as a non-empty queue, and the number of non-empty queues in the task queue is determined as the number of non-empty queues; Generate at least one task thread, and in response to the number of threads of the task thread being less than the number of non-empty queues, generate a new task thread. Among them, the task thread includes a scanning sub-thread, a cancellation sub-thread, and a download sub-thread; The scanning sub-thread is used to scan each of the task queues, and in response to not scanning a non-empty queue, re-scan each of the task queues; The cancellation sub-thread is used to count the number of scans of the scanning sub-thread. If the number of scans is greater than or equal to a preset number threshold, cancel the task thread; The download sub-thread is used to, if the scanning sub-thread scans a non-empty queue, clear the number of scans, retrieve permission tasks from the scanned non-empty queue, and execute the retrieved permission tasks; After obtaining a task queue corresponding to at least one requesting device, generate a request scheduling thread. The request scheduling thread includes a receiving sub-thread, a determining sub-thread, a calculating sub-thread, a first adding sub-thread, and a second adding sub-thread; the receiving sub-thread is used to receive a device permission request sent by a client and a device identifier corresponding to the device permission request. Among them, the device permission request includes at least one request task; the determining sub-thread is used to determine a target device corresponding to the device permission request from the requesting devices according to the device identifier, and determine the task queue corresponding to each of the target devices as a target queue; the calculating sub-thread is used to calculate the current number of tasks of the permission tasks in each of the target queues according to a preset queue length threshold to obtain the remaining task quantity of each of the target queues; the first adding sub-thread is used to, if the number of request tasks in the device permission request is less than or equal to the remaining task quantity of any target queue, add the request task as a permission task to the target queue; the second adding sub-thread is used to, if the number of request tasks in the device permission request is greater than the remaining task quantity of any target queue, determine a first task from the request tasks according to the remaining task quantity, add the first task as a permission task to the target queue, and add a second task as a dormant task to a preset task storage space. Among them, the second task includes request tasks other than the first task.
2. The method according to claim 1, characterized in that, After obtaining a task queue corresponding to at least one requesting device, the method further includes: Generate a request receiving thread, where the request receiving thread is used to receive a device permission request sent by a client and a device identifier corresponding to the device permission request. The device permission request includes at least one request task, determine a target device corresponding to the device permission request from the requesting devices according to the device identifier, determine the request task as a dormant task corresponding to the target device, and store the dormant task in a preset task storage space.
3. The method according to claim 1, characterized in that After generating the request scheduling thread, the method further includes: Generating a task wake-up thread, which is used to count the current number of permission tasks in each of the task queues every preset first time interval. If the current number of permission tasks in any task queue is less than the queue length threshold, select the dormant tasks corresponding to the task queue from the task storage space, and store the selected dormant tasks as new permission tasks into the task queue.
4. The method according to claim 1, wherein In response to the number of threads of the task thread being less than the number of non-empty queues in the task queue, generating a new task thread, including: Generating a management thread, which is used to count the number of threads of the task thread and the number of non-empty queues in the task queue every preset second time interval. If the number of threads meets the first preset condition and the second preset condition, generate a new task thread. If the number of threads does not meet the first preset condition or the second preset condition, reject generating a new task thread. Among them, the first preset condition includes that the number of threads is less than the number of non-empty queues in the task queue, and the second preset condition includes that the number of threads is less than the preset maximum thread threshold.
5. The method according to claim 1, wherein The sub-thread for cancellation cancels the task thread by the following method: Compare the number of threads of all task threads with the preset minimum thread threshold; If the number of threads is greater than the minimum thread threshold, cancel the task thread where the sub-thread for cancellation is located; If the number of threads is less than or equal to the minimum thread threshold, rescan each of the task queues.
6. The method according to claim 1, wherein The sub-thread for download is further used for: If the sub-thread for scanning scans a non-empty queue, determine the current state of the non-empty queue as the locked state; After executing the retrieved permission task, determine the current state of the non-empty queue as the scanning state; Among them, if the non-empty queue is in the locked state, the non-empty queue cannot be scanned by any task thread.
7. A multi-thread based permission task execution system, characterized in that, Including: An acquisition module, which is used to acquire the task queues corresponding to at least one requesting device. The task queues are used to store the permission tasks of the requesting device. Among them, the task queue storing at least one permission task is determined as a non-empty queue, and the number of non-empty queues in the task queue is determined as the number of non-empty queues; A generation module, which is used to generate at least one task thread. Among them, the task thread includes a scanning sub-thread, a cancellation sub-thread, and a download sub-thread. The scanning sub-thread is used to scan each of the task queues, and in response to not scanning a non-empty queue, rescan each of the task queues. The cancellation sub-thread is used to count the number of scans of the scanning sub-thread. If the number of scans is greater than or equal to the preset number threshold, cancel the task thread. The download sub-thread is used to, if the scanning sub-thread scans a non-empty queue, clear the number of scans, retrieve the permission task from the scanned non-empty queue, and download the retrieved permission task to the corresponding requesting device; A new module, configured to generate a new task thread in response to the number of threads of the task thread being less than the number of non-empty queues; The obtaining module is further configured to, after obtaining the task queues corresponding to at least one requesting device, generate a request scheduling thread, where the request scheduling thread includes a receiving sub-thread, a determining sub-thread, a calculating sub-thread, a first adding sub-thread, and a second adding sub-thread; the receiving sub-thread is configured to receive a device permission request sent by a client and a device identifier corresponding to the device permission request, where the device permission request includes at least one request task; the determining sub-thread is configured to determine, according to the device identifier, a target device corresponding to the device permission request from the requesting devices, and determine the task queues corresponding to the target devices as target queues; the calculating sub-thread is configured to calculate the current number of tasks of the permission tasks in each target queue according to a preset queue length threshold to obtain the number of free tasks in each target queue; the first adding sub-thread is configured to, if the number of request tasks in the device permission request is less than or equal to the number of free tasks in any target queue, add the request tasks as permission tasks to the target queue; the second adding sub-thread is configured to, if the number of request tasks in the device permission request is greater than the number of free tasks in any target queue, determine a first task from the request tasks according to the number of free tasks, add the first task as a permission task to the target queue, and add a second task as a dormant task to a preset task storage space, where the second task includes the request tasks other than the first task.
8. An electronic device, characterized in that, Comprising: A processor and a memory; The memory is configured to store a computer program, and the processor is configured to execute the computer program stored in the memory, so that the electronic device executes the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, on which a computer program is stored, characterized in that: The computer program, when executed by a processor, implements the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Task processing method and device, electronic equipment and storage medium
CN114490123A
Method and device for adjusting number of threads and computing equipment
CN114510331A