A thread processing method, system and medium based on a thread pool and an object pool

Through the optimization processing methods of thread pools and object pools, the problems of high server pressure and high development difficulty in game thread processing are solved, and efficient resource management and user experience are improved.

CN113867954BActive Publication Date: 2025-07-25SUZHOU JIUGONG DIGITAL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111135214.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-27
Publication Date
2025-07-25
Estimated Expiration
2041-09-27

AI Technical Summary

Technical Problem

The existing game thread processing methods lead to high pressure on servers, high development difficulty, high cost and low user experience, and it is difficult for the existing technology to efficiently process user concurrent commands.

Method used

Using processing methods based on thread pools and object pools, the use of threads and object pools is optimized to achieve efficient event processing and resource management by initializing configuration, event storage and processing modules.

Benefits of technology

It reduces server resource consumption, improves development efficiency and user experience, reduces server usage costs, and improves server operation quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113867954B_ABST
    Figure CN113867954B_ABST
Patent Text Reader

Abstract

The present invention discloses a thread processing method, system and medium based on a thread pool and an object pool. The method includes the following steps: obtaining the startup request situation of game threads; configuring a first thread pool based on the startup request situation; setting the object pool specification based on the game threads and the first thread pool, and configuring a first object pool based on the object pool specification; constructing a blocking queue; obtaining the event execution status of game threads; obtaining the available object situation of the first object pool based on the event execution status; storing the first task event of the game threads into the blocking queue based on the available object situation; setting a first queue position of the blocking queue; performing an event processing operation on the first task event in the blocking queue based on the first queue position; performing an object return operation based on the processing result of the event processing operation. The present invention can save the server resources consumed by game operation and improve the development efficiency and the working efficiency of the server through the design of the thread pool and the object pool.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of game thread processing, and particularly to a thread processing method, system and medium based on a thread pool and an object pool. Background Art

[0002] In the prior art, the command pattern is adopted for processing user behaviors in game threads. In this pattern, when processing concurrent commands of users, continuous processing operations and object destruction operations will be carried out according to the generation of user commands. Being in this pattern for a long time will cause great pressure on the server, and at the same time reduce the utilization efficiency of the server. Correspondingly, when the server capacity is insufficient, the method of opening a new server is adopted to meet the requirements of game threads. This way will ultimately increase the development difficulty of developers, increase the usage cost of the server, and reduce the working efficiency of the server and the user experience. Summary of the Invention

[0003] The present invention mainly solves the problem that the existing game thread processing method will increase the development difficulty of developers, increase the usage cost of the server, and reduce the working efficiency of the server and the user experience.

[0004] To solve the above technical problems, a technical solution adopted by the present invention is: to provide a thread processing method based on a thread pool and an object pool, including the following steps:

[0005] Initialization step:

[0006] Configure a retrieval function, a constructor, a pool threshold, a thread pool specification matching table, a specification percentage matching table, and a computing resource matching table; obtain the startup request situation of the game thread; configure a first thread pool based on the retrieval function, the constructor, the pool threshold, the thread pool specification matching table, and the startup request situation; set the object pool specification based on the specification percentage matching table, the computing resource matching table, the game thread, and the first thread pool, and configure a first object pool based on the object pool specification.

[0007] Event storage step:

[0008] Construct a blocking queue; configure a hash algorithm, a first placement strategy, an event addition function, a delay threshold, and a detection time period; obtain the event execution status of the game thread; obtain the available object situation of the first object pool based on the delay threshold, the detection time period, and the event execution status; store the first task event of the game thread into the blocking queue based on the hash algorithm, the first placement strategy, the event addition function, and the available object situation.

[0009] Event processing step:

[0010] Set the first queue bit of the blocking queue; configure the event execution function and the event return function; perform an event processing operation on the first task event in the blocking queue based on the first queue bit and the event execution function; perform an object return operation based on the event return function and the processing result of the event processing operation.

[0011] As an improved solution, the step of configuring the first thread pool based on the retrieval function, the construction function, the pool threshold, the thread pool specification matching table, and the start request situation further includes:

[0012] When the start request situation is a start request for a game thread, obtain the thread information in the start request; identify the thread type in the thread information;

[0013] Call the retrieval function to retrieve the thread pool specification matching table, and filter out the thread pool specification information that matches the thread type in the thread pool specification matching table;

[0014] Detect the pool quantity of the second thread pool in the game background, compare whether the pool quantity reaches the pool threshold, if not, call the construction function to create a thread array that matches the thread pool specification information, and set the thread array as the first thread pool.

[0015] As an improved solution, the step of setting the object pool specification based on the specification percentage matching table, the computing resource matching table, the game thread, and the first thread pool, and configuring the first object pool based on the object pool specification further includes:

[0016] Store the game thread in the first thread pool; identify the first space resource value occupied by the game thread in the first thread pool; obtain the second space resource value of the first thread pool;

[0017] Calculate the ratio of the first space resource value to the second space resource value to obtain the resource occupancy percentage; filter out the object pool specification that matches the resource occupancy percentage in the specification percentage matching table; filter out the computing resource quantity that matches the object pool specification in the computing resource matching table;

[0018] Divide a buffer area that matches the object pool specification in the virtual memory of the server where the game thread is located; configure computing resource nodes that match the computing resource quantity in the buffer area to obtain the first object pool.

[0019] As an improved solution, the step of obtaining the available object situation of the first object pool based on the delay threshold, the detection time period, and the event execution status further includes:

[0020] When the event execution status indicates that there are pending events in the game thread, obtain the call logs of computing resource nodes in the server; count the number of first nodes that match the computing resource nodes in the call logs of the computing resource nodes; compare whether the number of first nodes reaches the computing resource quantity; if it reaches, perform a delay determination operation based on the delay threshold and the detection time period; if it does not reach, set the available object situation to that there are available objects.

[0021] As an improved solution, the delay determination operation includes:

[0022] Obtain a first time point; calculate the sum of the first time point and the delay threshold to obtain a second time point; within the time period between the first time point and the second time point, obtain the number of first nodes at intervals of the detection time period;

[0023] If the number of first nodes does not reach the computing resource quantity, set the available object situation to that there are available objects; if the number of first nodes reaches the computing resource quantity, set the available object situation to that there are no available objects.

[0024] As an improved solution, the first placement strategy includes: when storing the first task event, place the first task event at the end of the blocking queue based on the time order of several second task events in the blocking queue;

[0025] The step of storing the first task event of the game thread into the blocking queue based on the hash algorithm, the first placement strategy, the event addition function, and the available object situation further includes:

[0026] When the available object situation is that there are available objects, identify the position information and identification information of the game thread in the first thread pool; create thread index information of the game thread based on the position information; integrate the identification information and the thread index information to obtain the execution parameters of the game thread;

[0027] Call the hash algorithm to process the thread index information to obtain the task subscript of the game thread; create the first task event that matches the game process based on the execution parameters and the task subscript through the event addition function;

[0028] Obtain the queue sequence information of the blocking queue, confirm the second queue position in the blocking queue that matches the first placement strategy based on the queue sequence information; place the first task event into the second queue position.

[0029] As an improved solution, the event handling operation includes:

[0030] Identifying the queue bit information of the first task event in the blocking queue; when the queue bit information indicates that the first task event reaches the first event bit, filtering out the available nodes in the first object pool based on the call logs of the computing resource nodes;

[0031] Controlling the game thread to call the event execution function through the available nodes to retrieve the first task event from the blocking queue and execute the first task event; the event execution function is configured based on the run method;

[0032] Detecting whether there is feedback information for the first task event in the server; if so, setting the processing result as task execution success; if not, setting the processing result as task execution failure.

[0033] As an improved solution, the object return operation includes:

[0034] When the processing result is task execution success, controlling the game thread to call the event return function to return the available nodes called in the event handling operation to the first object pool; the event return function is configured based on the returnObject method.

[0035] The present invention also provides a thread processing system based on a thread pool and an object pool, including:

[0036] An initialization configuration module, an event storage module, and an event processing module;

[0037] A first configuration program is configured in the initialization module, and the first configuration program is used to configure a retrieval function, a constructor, a pool threshold, a thread pool specification matching table, a specification percentage matching table, and a computing resource matching table; the initialization module is used to obtain the startup request situation of the game thread and configure a first thread pool based on the retrieval function, the constructor, the pool threshold, the thread pool specification matching table, and the startup request situation; the initialization module sets the object pool specification based on the specification percentage matching table, the computing resource matching table, the game thread, and the first thread pool, and configures a first object pool based on the object pool specification;

[0038] A second configuration program is configured in the event storage module. The second configuration program is used to construct a blocking queue and configure a hash algorithm, a first placement policy, an event addition function, a delay threshold, and a detection time period. The event storage module is used to obtain the event execution status of the game thread and obtain the available object situation of the first object pool based on the delay threshold, the detection time period, and the event execution status. The event storage module stores the first task event of the game thread in the blocking queue based on the hash algorithm, the first placement policy, the event addition function, and the available object situation.

[0039] A third configuration program is configured in the event processing module. The third configuration program is used to set a first queue position of the blocking queue and configure an event execution function and an event return function. The event processing module is used to perform an event processing operation on the first task event in the blocking queue according to the first queue position and the event execution function. The event processing module performs an object return operation based on the event return function and the processing result of the event processing operation.

[0040] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the thread processing method based on a thread pool and an object pool are implemented.

[0041] The beneficial effects of the present invention are as follows:

[0042] 1. The thread processing method based on a thread pool and an object pool according to the present invention can achieve the design of a thread pool and an object pool, thereby saving the server resources consumed by game operation, reducing the difficulty of developers compiling business logic to a certain extent, improving the development efficiency and the working efficiency of the server, further enhancing the user experience, reducing the use cost of the server, making up for the deficiencies of the prior art, and having extremely high market influence.

[0043] 2. The thread processing system based on a thread pool and an object pool according to the present invention can realize the invocation of the thread pool and the object pool through the mutual cooperation of the initialization configuration module, the event storage module, and the event processing module, save the server resources consumed by game operation, reduce the difficulty of developers compiling business logic to a certain extent, improve the development efficiency and the working efficiency of the server, further enhance the user experience, reduce the use cost of the server, make up for the deficiencies of the prior art, and have extremely high market influence.

[0044] 3. The computer-readable storage medium of the present invention can enable the boot initialization configuration module, the event storage module, and the event processing module to cooperate, thereby realizing the invocation of the thread pool and the object pool, saving the server resources consumed by game operation, reducing the difficulty of developers in compiling business logic to a certain extent, improving the development efficiency and the working efficiency of the server, further enhancing the user experience, reducing the usage cost of the server, making up for the deficiencies of the prior art, having extremely high market influence, and effectively improving the operability of the thread processing method based on the thread pool and the object pool. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for use in the description of the specific embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0046] Figure 1 is a flowchart of the thread processing method based on the thread pool and the object pool according to Embodiment 1 of the present invention;

[0047] Figure 2 is a specific process schematic diagram of the thread processing method based on the thread pool and the object pool according to Embodiment 1 of the present invention;

[0048] Figure 3 is an architecture diagram of the thread processing system based on the thread pool and the object pool according to Embodiment 2 of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0049] The following will elaborate on the preferred embodiments of the present invention in conjunction with the drawings, so that the advantages and features of the present invention can be more easily understood by those skilled in the art, thereby making the protection scope of the present invention more clearly defined.

[0050] In the description of the present invention, it should be noted that the embodiments described in the present invention are some embodiments of the present invention, rather than all embodiments; based on the embodiments in the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present invention.

[0051] In the description of the present invention, it should be noted that the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.

[0052] In the description of the present invention, it should be noted that, unless otherwise clearly specified and defined, the terms "retrieval function", "constructor function", "pool threshold", "thread pool specification matching table", "specification percentage matching table", "computing resource matching table", "start request situation", "thread pool", "object pool specification", "object pool", "blocking queue", "hash algorithm", "placement strategy", "event addition function", "delay threshold", "detection time period", "event execution status", "available object situation", "queue bit", "event execution function", "event return function", "event processing operation", "processing result", "object return operation", "existence of a start request for a game thread", "thread information", "thread type", "thread pool specification information", "pool quantity", "thread array", "space resource value", "resource occupancy percentage", "computing resource quantity", "buffer area", "virtual memory", "computing resource node", "computing resource node call log", "node quantity", "delay determination operation", "time point", "time sequence", "last bit", "location information", "identification information", "thread index information", "execution parameter", "task subscript", "task event", "queue sequence information", "queue bit information", "run method", "feedback information", "returnObject method", "initialization configuration module", "event storage module", "event processing module", "configuration program" should be understood in a broad sense. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific situations.

[0053] In the description of the present invention, it should be noted that: Java is an object-oriented programming language; the CPU (Central Processing Unit) is the central processing unit.

[0054] Embodiment 1

[0055] This embodiment provides a thread processing method based on a thread pool and an object pool, as Figure 1 and Figure 2 shown, including the following steps:

[0056] S100. Initialization step:

[0057] Step S100 specifically includes:

[0058] S101. Configure a retrieval function, a constructor, a pool threshold, a thread pool specification matching table, a specification percentage matching table, and a computing resource matching table; obtain the startup request situation of game threads; configure a first thread pool based on the retrieval function, the constructor, the pool threshold, the thread pool specification matching table, and the startup request situation; set the object pool specification based on the specification percentage matching table, the computing resource matching table, the game threads, and the first thread pool, and configure a first object pool based on the object pool specification; in this embodiment, the method includes but is not limited to being developed and compiled through the Java language; correspondingly, both the retrieval function and the constructor are implemented using functional statements in the Java language; the pool threshold is the upper limit number of thread pools pre-set within the server, used to limit the server's load capacity and further improve the server's working efficiency and stability; the thread pool specification matching table is a data set containing several mapping relationships in which the thread pool specification matches the thread type; the specification percentage matching table is a data set containing several mapping relationships in which the object pool specification matches the resource occupancy percentage; the computing resource matching table is a data set containing several mapping relationships in which the computing resource quantity matches the object pool specification;

[0059] Specifically, when the startup request situation is that there is a startup request for a game thread, obtain the thread information in the startup request; identify the thread type in the thread information; the judgment criterion for the existence of a startup request for a game thread is that there are game commands, game behaviors, game copies, game tasks, etc. that need to be executed in the game thread; correspondingly, the thread information includes but is not limited to the number of threads, the matching degree between the thread and the CPU, the specific information of the CPU thread occupied by the thread, the type of the thread, etc.; correspondingly, the thread type includes but is not limited to dynamic threads and static threads; call the retrieval function to retrieve the thread pool specification matching table, and filter out the thread pool specification information that matches the thread type in the thread pool specification matching table; in this embodiment, in order to ensure that the utilization rate of the thread pool reaches the maximum, the specification information that fits the thread type is selected to set the size of the thread pool; correspondingly, since the thread pool will not be dynamically expanded after being set, this will improve the stability of the server, reduce performance loss, and prevent thread expansion; correspondingly, the thread pool specification matching table can be set according to specific circumstances, for example, set the corresponding thread pool specification matching table according to the game type or the game running scale; detect the number of pools in the game background of the second thread pool, and compare whether the number of pools reaches the pool threshold. If not, call the constructor to create a thread array that matches the thread pool specification information, and set the thread array as the first thread pool; correspondingly, in this embodiment, only when the number of pools does not reach the pool threshold, it means that a corresponding thread pool can be created in the game background of the server; through the verification and detection of the number of pools and the pool threshold, it can be ensured that the server is always in a high-quality running state, and further improve the efficiency of the server and the game background in processing game threads; in this embodiment, part of the implementation code of this step is as follows:

[0060] public class GameThreadPool {

[0061] private GameThread[] threads;

[0062] private int poolSize;

[0063] @param threadNum

[0064] public GameThreadPool(int threadNum) {

[0065] threads = new GameThread[threadNum];

[0066] poolSize = threadNum;

[0067] for (int i = 0; i < threadNum; i++) {

[0068] GameThread thread = new GameThread(i);

[0069] Specifically, store the game thread in the first thread pool; identify the first space resource value occupied by the game thread in the first thread pool; obtain the second space resource value of the first thread pool; in this embodiment, the first space resource value is the real-time occupancy value of the first thread pool occupied by the first thread pool, including but not limited to storage occupancy and network occupancy, etc.; the second space resource value is the total space resource value of the first thread pool, including but not limited to the total storage capacity and total network bandwidth, etc.; correspondingly, the first space resource value matches the second space resource value; calculate the ratio of the first space resource value to the second space resource value to obtain the resource occupancy percentage; screen out the object pool specification that matches the resource occupancy percentage in the specification percentage matching table; screen out the computing resource quantity that matches the object pool specification in the computing resource matching table; this step is also to reduce resource waste and set the object pool specification that matches the game thread; divide a buffer area that matches the object pool specification in the virtual memory of the server where the game thread is located; configure computing resource nodes that match the computing resource quantity in the buffer area to obtain the first object pool; in this embodiment, use the virtual memory of the server, thereby reducing the burden on the server, improving the working efficiency of the server, and at the same time, without external storage space, reducing the use cost of the server; in this embodiment, the computing resource nodes include but not limited to computing nodes, processing nodes, information transmission nodes, etc.; the object pool specification is 1024GB, and includes but not limited to 1024GB; correspondingly, part of the implementation code for creating the first object pool is as follows:

[0070] GenericObjectPoolConfig <gameevent>config = newGenericObjectPoolConfig<>();

[0071] config.setMaxIdle(1);

[0072] config.setMinIdle(1);

[0073] config.setMaxTotal(1024);

[0074] this.objectPool = new GenericObjectPool<>(newGameEventObjectPool(),config);

[0075] S200, Event storage step:

[0076] Step S200 specifically includes:

[0077] S201. Construct a blocking queue; configure a hash algorithm, a first placement strategy, an event addition function, a delay threshold, and a detection time period; obtain the event execution status of the game thread; obtain the available object situation of the first object pool based on the delay threshold, the detection time period, and the event execution status; store the first task event of the game thread in the blocking queue based on the hash algorithm, the first placement strategy, the event addition function, and the available object situation; in this embodiment, the blocking queue is a first-in, first-out event storage queue, and correspondingly, the data structure of the blocking queue is LinkedBlockingQueue;

[0078] Specifically, when relevant tasks need to be executed in the game thread or the user of the game thread issues certain execution instructions, the event execution status is that there are pending events in the game thread; correspondingly, when the event execution status is that there are pending events in the game thread, obtain the call log of the computing resource nodes in the server, and this call log is the usage and allocation details information of several computing resource nodes in the server; count the number of the first nodes in the computing resource node call log that match the computing resource nodes; compare whether the number of the first nodes reaches the computing resource quantity; if it reaches, it means that there are no corresponding available objects in the first object pool and the processing of events or tasks in the game thread cannot be executed, so perform a delay determination operation based on the delay threshold and the detection time period; if it does not reach, it means that there are corresponding available objects in the first object pool and the processing of events or tasks in the game thread can be executed, so set the available object situation to the existence of available objects;

[0079] Specifically, the delay determination operation includes: obtaining a first time point, which is the current time point; correspondingly, the delay threshold is 500 ms and can be set according to specific circumstances; correspondingly, calculating the sum of the first time point and the delay threshold to obtain a second time point; within the time period between the first time point and the second time point, obtaining the number of the first nodes at every detection time period; in this step, through the setting of the delay threshold, the detection of available objects in the first object pool is delayed. Therefore, in the case of no available objects, wait for the duration of the delay threshold again to further wait for the appearance of available objects; therefore, when waiting for the duration of the delay threshold, if the number of the first nodes does not reach the number of computing resources, set the available object situation as the existence of available objects; if the number of the first nodes reaches the number of computing resources, set the available object situation as the non-existence of available objects; through the delay determination operation, the accuracy of the determination of the available object situation is further improved, and the situation of the lack of available objects caused by abnormal situations in the server is further avoided, improving the accuracy of the entire process;

[0080] Specifically, the first placement strategy includes: when storing the first task event, placing the first task event at the end of the blocking queue based on the chronological order of several second task events in the blocking queue; correspondingly, the first placement strategy is an execution strategy of first in, first out according to the chronological order of task event addition in the blocking queue; when the available object situation is that there are available objects, identifying the position information and identification information of the game thread in the first thread pool; correspondingly, the identification information is the unique identifier of the game thread in the first thread pool, including but not limited to the game thread ID number, etc.; creating thread index information of the game thread based on the position information; integrating the identification information and the thread index information to obtain the execution parameters of the game thread; the execution parameters are the executable information of the game thread and several parameter information, and the game thread can be called by invoking this information; invoking the hash algorithm to process the thread index information to obtain the task subscript of the game thread; the task subscript is the subscript of the game thread, mainly used to obtain and control the corresponding game thread; creating the first task event matching the game process based on the execution parameters and the task subscript through the event addition function; in this embodiment, the event addition function is implemented based on the addEvent method statement of Java; obtaining the game thread based on the task subscript and passing the execution parameters into the obtained game thread through the addEvent method, that is, obtaining the corresponding first task event to be executed; obtaining the queue sequence information of the blocking queue, and confirming the second queue position in the blocking queue that matches the first placement strategy based on the queue sequence information; placing the first task event into the second queue position; in this embodiment, the queue sequence information is the sorting information of several pending events in the blocking queue; the second queue position must be the end position in the blocking queue; after finding the end position, the first task event is placed into the blocking queue; the blocking queue can ensure that when a task is executed, the extraction and execution of other tasks are blocked, further ensuring the execution quality and efficiency of the current task and further improving the working efficiency of the server; in this embodiment, the partial implementation code for processing the thread index information by the hash algorithm is as follows:

[0081] public GameThread getThreadById(long uniqueId) throwsIllegalGameThreadIndexException {

[0082] int index = hash(uniqueId);

[0083] if (index >= threads.length) {

[0084] throw new IllegalGameThreadIndexException(deskId,index);

[0085] }

[0086] return threads[index];

[0087] }

[0088] private int hash(long key){

[0089] return (int)(key%poolSize);

[0090] }

[0091] The partial implementation code for placing an event into the queue is as follows:

[0092] public void addEvent(Desk desk, long playerId, GameEventType gameEventType, Object... param)

[0093] S300. Event processing steps:

[0094] Step S300 specifically includes:

[0095] S301. Set the first queue position of the blocking queue; configure an event execution function and an event return function; perform an event processing operation on the first task event in the blocking queue based on the first queue position and the event execution function; perform an object return operation based on the event return function and the processing result of the event processing operation; in this embodiment, the first queue position is the head of the blocking queue;

[0096] Specifically, the event handling operation includes: identifying the queue bit information of the first task event in the blocking queue; when the queue bit information indicates that the first task event reaches the first event bit, filtering out the available nodes in the first object pool based on the computing resource node call logs; correspondingly, this step means that the first task event to be processed reaches the head of the blocking queue, that is, there are no pending events between the first task events. Therefore, based on the computing resource node call logs, the uninvoked computing resource nodes in the first object pool are filtered out, and these computing resource nodes are set as available nodes; controlling the game thread to call the event execution function through the available nodes to take out the first task event from the blocking queue and execute the first task event; the event execution function is configured based on the run method; detecting whether there is feedback information for the first task event in the server; if it exists, setting the processing result as successful task execution; if it does not exist, setting the processing result as failed task execution; in this embodiment, the feedback information includes, but is not limited to, the confirmation operation or interaction operation of the user of the game thread for the game task or game command, etc.; specifically, the object return operation includes: when the processing result is successful task execution, controlling the game thread to call the event return function to return the available nodes called in the event handling operation to the first object pool; the event return function is configured based on the returnObject method; in this embodiment, partial implementation codes for the event handling operation and the object return operation are as follows:

[0097] / / Event handling operation

[0098] public void run() {

[0099] while (true) {

[0100] try {

[0101] GameEvent event = queue.take();

[0102] } catch (Exception e) {

[0103] e.printStackTrace();

[0104] } finally {

[0105] / / Object return operation

[0106] objectPool.returnObject(event);

[0107] }

[0108] }

[0109] }

[0110] Through the thread processing method based on the thread pool and the object pool described in this embodiment, the commands or behaviors of game users can be executed correspondingly in an orderly and efficient manner. In the face of real-time commands or behaviors of users, there is no need to meet the game thread requirements by opening a new server. Only the mutual calls between the object pool and the thread pool are required to process the corresponding game commands or behaviors. The program compiled based on this method has a relatively low development difficulty. The calls of the object pool and the thread pool improve the running quality and work efficiency of the server, ultimately saving the loss of server resources during the game operation, reducing the server usage cost, making up for the deficiencies of the existing technology, and greatly improving the user experience.

[0111] Embodiment 2

[0112] This embodiment provides a thread processing system based on a thread pool and an object pool, as Figure 3 shown, including: an initialization configuration module, an event storage module, and an event processing module;

[0113] In the thread processing system based on the thread pool and the object pool, a first configuration program is configured in the initialization module. The first configuration program is used to configure a retrieval function, a constructor, a pool threshold, a thread pool specification matching table, a specification percentage matching table, and a computing resource matching table; the initialization module is used to obtain the startup request situation of the game thread, and configure a first thread pool based on the retrieval function, the constructor, the pool threshold, the thread pool specification matching table, and the startup request situation; the initialization module sets the object pool specification based on the specification percentage matching table, the computing resource matching table, the game thread, and the first thread pool, and configures a first object pool based on the object pool specification;

[0114] Specifically, when the startup request situation is that there is a startup request for a game thread, the initialization module obtains the thread information in the startup request and identifies the thread type in the thread information; the initialization module calls the retrieval function to retrieve the thread pool specification matching table, and filters out the thread pool specification information matching the thread type in the thread pool specification matching table; the initialization module detects the pool quantity of the second thread pool in the game background, and compares whether the pool quantity reaches the pool threshold. If not, the initialization module calls the constructor to create a thread array matching the thread pool specification information, and sets the thread array as the first thread pool;

[0115] Specifically, the initialization module stores the game thread in the first thread pool and identifies the first space resource value occupied by the game thread in the first thread pool; the initialization module obtains the second space resource value of the first thread pool; the initialization module calculates the ratio of the first space resource value to the second space resource value to obtain the resource occupancy percentage; the initialization module filters out the object pool specification that matches the resource occupancy percentage in the specification percentage matching table; the initialization module filters out the computing resource quantity that matches the object pool specification in the computing resource matching table; the initialization module divides a buffer area that matches the object pool specification in the virtual memory of the server where the game thread is located; the initialization module configures computing resource nodes that match the computing resource quantity in the buffer area to obtain the first object pool.

[0116] In the thread processing system based on the thread pool and the object pool, a second configuration program is configured in the event storage module. The second configuration program is used to construct a blocking queue and configure a hash algorithm, a first placement strategy, an event addition function, a delay threshold, and a detection time period; the event storage module is used to obtain the event execution status of the game thread and obtain the available object situation of the first object pool based on the delay threshold, the detection time period, and the event execution status; the event storage module stores the first task event of the game thread in the blocking queue based on the hash algorithm, the first placement strategy, the event addition function, and the available object situation.

[0117] Specifically, when the event execution status is that there are pending events in the game thread, the event storage module obtains the computing resource node call log in the server and counts the first node quantity of the nodes that match the computing resource node in the computing resource node call log; the event storage module compares whether the first node quantity reaches the computing resource quantity; if it reaches, the event storage module performs a delay determination operation based on the delay threshold and the detection time period; if it does not reach, the event storage module sets the available object situation to that there are available objects.

[0118] Specifically, the delay determination operation includes: the event storage module obtains a first time point and calculates the sum of the first time point and the delay threshold to obtain a second time point; the event storage module obtains the first node quantity every detection time period within the time period between the first time point and the second time point; if the first node quantity does not reach the computing resource quantity, the event storage module sets the available object situation to that there are available objects; if the first node quantity reaches the computing resource quantity, the event storage module sets the available object situation to that there are no available objects.

[0119] Specifically, the first placement strategy includes: when storing the first task event, placing the first task event at the end of the blocking queue based on the chronological order of several second task events in the blocking queue;

[0120] Specifically, when the available object situation is that there are available objects, the event storage module identifies the position information and identification information of the game thread in the first thread pool; the event storage module creates thread index information of the game thread based on the position information; the event storage module integrates the identification information and the thread index information to obtain the execution parameters of the game thread; the event storage module calls the hash algorithm to process the thread index information to obtain the task subscript of the game thread; the event storage module creates the first task event matching the game process based on the execution parameters and the task subscript through the event addition function; the event storage module obtains the queue sequence information of the blocking queue and confirms the second queue position in the blocking queue that matches the first placement strategy based on the queue sequence information; the event storage module places the first task event in the second queue position.

[0121] In the thread processing system based on the thread pool and the object pool, a third configuration program is configured in the event processing module. The third configuration program is used to set the first queue position of the blocking queue and configure an event execution function and an event return function; the event processing module is used to perform an event processing operation on the first task event in the blocking queue according to the first queue position and the event execution function; the event processing module performs an object return operation based on the event return function and the processing result of the event processing operation;

[0122] Specifically, the event processing operation includes: the event processing module identifies the queue position information of the first task event in the blocking queue; when the queue position information is that the first task event reaches the first event position, the event processing module filters out the available nodes in the first object pool based on the computing resource node call log; the event processing module controls the game thread to call the event execution function through the available nodes to take out the first task event from the blocking queue and execute the first task event; correspondingly, the event execution function is configured by the event processing module based on the run method; the event processing module detects whether there is feedback information for the first task event in the server; if it exists, the event processing module sets the processing result to task execution success; if it does not exist, the event processing module sets the processing result to task execution failure;

[0123] Specifically, the object return operation includes: when the processing result is that the task is successfully executed, the event processing module controls the game thread to call the event return function to return the available nodes called in the event processing operation to the first object pool; the event return function is configured by the event processing module based on the returnObject method.

[0124] Through the thread processing system based on the thread pool and the object pool described in this embodiment, through the mutual cooperation between the initialization configuration module, the event storage module and the event processing module, the corresponding execution processing can be carried out in an orderly and efficient manner for the commands or behaviors of game users. Moreover, in the face of real-time commands or behaviors of users, there is no need to open a new server to meet the game thread requirements. Only the mutual call between the object pool and the thread pool is required to process the corresponding game commands or behaviors. The overall development difficulty of this system is relatively low. The call of the object pool and the thread pool improves the operation quality and work efficiency of the server, ultimately saving the loss of server resources during the game operation, reducing the server usage cost, making up for the deficiencies of the prior art, and greatly improving the user experience.

[0125] Embodiment 3

[0126] This embodiment provides a computer-readable storage medium, including:

[0127] The storage medium is used to store the computer software instructions used to implement the thread processing method based on the thread pool and the object pool described in the above Embodiment 1, and it contains a program set for executing the thread processing method based on the thread pool and the object pool; specifically, this executable program can be built into the thread processing system based on the thread pool and the object pool described in Embodiment 2. In this way, the thread processing system based on the thread pool and the object pool can implement the thread processing method based on the thread pool and the object pool described in the above Embodiment 1 by executing the built-in executable program.

[0128] In addition, the computer-readable storage medium of this embodiment can adopt any combination of one or more readable storage media, where the readable storage media include electrical, optical, electromagnetic, infrared or semiconductor systems, devices or components, or any combination of the above.

[0129] Different from the prior art, adopting a thread processing method, system and medium based on a thread pool and an object pool in this application can save the server resources consumed in game operation by calling the thread pool and the object pool in this method, reduce the difficulty of developers compiling business logic to a certain extent, improve the development efficiency and the work efficiency of the server, provide effective technical support for this method through this system, further improve the user experience, and ultimately reduce the server usage cost, making up for the deficiencies of the prior art.

[0130] The serial numbers of the disclosed embodiments of the present invention are only for description and do not represent the superiority or inferiority of the embodiments.

[0131] Those of ordinary skill in the art can understand that all or part of the steps to implement the above embodiments can be completed by hardware, or a program for instructing the relevant hardware to complete can be stored in a computer-readable storage medium. The above-mentioned storage medium can be a read-only memory, a magnetic disk, an optical disk, etc.

[0132] The above is only the embodiment of the present invention, and thus does not limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present invention.< / gameevent>

Claims

1. A thread processing method based on a thread pool and an object pool, characterized in that, It includes the following steps: Initialization step: Configure a retrieval function, a constructor, a pool threshold, a thread pool specification matching table, a specification percentage matching table, and a computing resource matching table; obtain the startup request situation of the game thread; configure a first thread pool based on the retrieval function, the constructor, the pool threshold, the thread pool specification matching table, and the startup request situation; Set the object pool specification based on the specification percentage matching table, the computing resource matching table, the game thread, and the first thread pool, and configure a first object pool based on the object pool specification; The step of configuring the first thread pool based on the retrieval function, the constructor, the pool threshold, the thread pool specification matching table, and the startup request situation further includes: when the startup request situation indicates that there is a startup request for the game thread, obtain the thread information in the startup request; identify the thread type in the thread information; call the retrieval function to retrieve the thread pool specification matching table, and filter out the thread pool specification information matching the thread type in the thread pool specification matching table; detect the number of pools in the second thread pool in the game background, and compare whether the number of pools reaches the pool threshold. If not, call the constructor to create a thread array matching the thread pool specification information, and set the thread array as the first thread pool; The step of setting the object pool specification based on the specification percentage matching table, the computing resource matching table, the game thread, and the first thread pool, and configuring the first object pool based on the object pool specification further includes: storing the game thread in the first thread pool; identifying the first space resource value occupied by the game thread in the first thread pool; obtaining the second space resource value of the first thread pool; calculating the ratio of the first space resource value to the second space resource value to obtain the resource occupancy percentage; filtering out the object pool specification matching the resource occupancy percentage in the specification percentage matching table; filtering out the computing resource quantity matching the object pool specification in the computing resource matching table; partitioning a buffer area matching the object pool specification in the virtual memory of the server where the game thread is located; configuring computing resource nodes matching the computing resource quantity in the buffer area to obtain the first object pool; Event storage step: Construct a blocking queue; configure a hash algorithm, a first placement strategy, an event addition function, a delay threshold, and a detection time period; obtain the event execution status of the game thread; obtain the available object situation of the first object pool based on the delay threshold, the detection time period, and the event execution status; store the first task event of the game thread in the blocking queue based on the hash algorithm, the first placement strategy, the event addition function, and the available object situation; Event processing step: Set the first queue position of the blocking queue; configure an event execution function and an event return function; perform an event processing operation on the first task event in the blocking queue based on the first queue position and the event execution function; perform an object return operation based on the event return function and the processing result of the event processing operation.

2. The thread processing method based on a thread pool and an object pool according to claim 1, wherein The step of obtaining the available object situation of the first object pool based on the delay threshold, the detection time period, and the event execution status further includes: When the event execution status is that there are pending events in the game thread, obtain the computing resource node call log in the server; count the number of first nodes that match the computing resource nodes in the computing resource node call log; compare whether the number of first nodes reaches the computing resource quantity; if it reaches, perform a delay determination operation based on the delay threshold and the detection time period; if it does not reach, set the available object situation to that there are available objects.

3. The thread processing method based on a thread pool and an object pool according to claim 2, wherein The delay determination operation includes: Obtain a first time point; calculate the sum of the first time point and the delay threshold to obtain a second time point; within the time period between the first time point and the second time point, obtain the number of first nodes at each detection time period. If the number of first nodes does not reach the computing resource quantity, set the available object situation to that there are available objects; if the number of first nodes reaches the computing resource quantity, set the available object situation to that there are no available objects.

4. The thread processing method based on a thread pool and an object pool according to claim 3, wherein The first placement strategy includes: when storing the first task event, place the first task event at the end of the blocking queue based on the time sequence of several second task events in the blocking queue. The step of storing the first task event of the game thread into the blocking queue based on the hash algorithm, the first placement strategy, the event addition function, and the available object situation further includes: When the available object situation is that there are available objects, identify the position information and identification information of the game thread in the first thread pool; create thread index information of the game thread based on the position information; integrate the identification information and the thread index information to obtain the execution parameters of the game thread. Call the hash algorithm to process the thread index information to obtain the task subscript of the game thread; create the first task event matching the game thread based on the execution parameters and the task subscript through the event addition function. Obtain the queue sequence information of the blocking queue, confirm the second queue position in the blocking queue that matches the first placement strategy based on the queue sequence information; place the first task event into the second queue position.

5. The thread processing method based on a thread pool and an object pool according to claim 4, characterized in that, The event processing operation includes: Identify the queue position information of the first task event in the blocking queue; when the queue position information is that the first task event reaches the first event position, filter out the available nodes in the first object pool based on the computing resource node call log. Control the game thread to call the event execution function through the available nodes to retrieve the first task event from the blocking queue and execute the first task event; the event execution function is configured based on the run method; Detect whether there is feedback information for the first task event in the server; if it exists, set the processing result to successful task execution; if it does not exist, set the processing result to failed task execution.

6. The thread processing method based on a thread pool and an object pool according to claim 5, wherein The object return operation includes: When the processing result is successful task execution, control the game thread to call the event return function to return the available nodes called in the event processing operation to the first object pool; the event return function is configured based on the returnObject method.

7. A thread processing system based on a thread pool and an object pool for the thread processing method based on a thread pool and an object pool according to claim 1, characterized in that, Includes: An initialization configuration module, an event storage module, and an event processing module; A first configuration program is configured in the initialization configuration module, and the first configuration program is used to configure a retrieval function, a constructor, a pool threshold, a thread pool specification matching table, a specification percentage matching table, and a computing resource matching table; the initialization configuration module is used to obtain the startup request situation of the game thread and configure a first thread pool based on the retrieval function, the constructor, the pool threshold, the thread pool specification matching table, and the startup request situation; the initialization configuration module sets the object pool specification based on the specification percentage matching table, the computing resource matching table, the game thread, and the first thread pool, and configures a first object pool based on the object pool specification; A second configuration program is configured in the event storage module, and the second configuration program is used to construct a blocking queue and configure a hash algorithm, a first placement strategy, an event addition function, a delay threshold, and a detection time period; the event storage module is used to obtain the event execution status of the game thread and obtain the available object situation of the first object pool based on the delay threshold, the detection time period, and the event execution status; the event storage module stores the first task event of the game thread in the blocking queue based on the hash algorithm, the first placement strategy, the event addition function, and the available object situation; A third configuration program is configured in the event processing module, and the third configuration program is used to set the first queue position of the blocking queue and configure an event execution function and an event return function; the event processing module is used to perform an event processing operation on the first task event in the blocking queue according to the first queue position and the event execution function; the event processing module performs an object return operation based on the event return function and the processing result of the event processing operation.

8. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, it implements the steps of the thread processing method based on a thread pool and an object pool according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Task execution method and device based on thread pool

    CN112835705A

  • Task processing method of resource pool and related equipment

    CN113204426A