A resource processing method and apparatus
Through the combination of exclusive and shared resource pools, the problem of low concurrency in multi-threaded programming is solved, and more efficient resource utilization and concurrency improvement are achieved.
Patent Information
- Application Number
- CN202011194968.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-30
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2041-07-11
AI Technical Summary
The existing pooling technology has low concurrency in multi-threaded programming, and multiple threads cannot run at the same time, resulting in reduced efficiency.
The combination of exclusive resource pool and shared resource pool is adopted. The thread exclusively occupies its corresponding resource pool and obtains resources from the shared resource pool when necessary to ensure that the thread can run independently.
Improve the concurrency of multi-threaded programming, avoiding the resource pool being locked by other threads, and improving resource utilization efficiency.
Smart Images

Figure CN112286687B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, and particularly to a resource processing method and apparatus. Background Art
[0002] Pooling technology can be used to improve the performance of a computer. The so-called pooling technology means that resources are created in advance and placed in a resource pool, and when resources are needed, they are directly obtained from the resource pool, avoiding the consumption of creating resources, thereby improving efficiency.
[0003] Currently, pooling technology can be applied to multithreaded programming. That is, multiple threads can all obtain resources from this resource pool. However, at most only one thread can use the resources in the resource pool at the same time, which makes multiple threads unable to run simultaneously, reducing concurrency. Summary of the Invention
[0004] The technical problem to be solved by this application is how to improve the concurrency when applying pooling technology to multithreaded programming, and provide a resource processing method and apparatus.
[0005] In a first aspect, an embodiment of this application provides a resource processing method, and the method includes:
[0006] Obtain resources from an exclusive resource pool corresponding to a first thread, where the exclusive resource pool corresponding to the first thread is used to provide resources for the first thread;
[0007] Use the obtained resources to run the first thread.
[0008] Optionally, before obtaining resources from the exclusive resource pool corresponding to the first thread, it further includes:
[0009] Determine that there are resources in the exclusive resource pool corresponding to the first thread.
[0010] Optionally, the method further includes:
[0011] In the case of determining that there are no resources in the exclusive resource pool corresponding to the first thread, lock a shared resource pool and obtain resources from the shared resource pool; where:
[0012] The resources in the shared resource pool are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0013] Optionally, before locking the shared resource pool and obtaining resources from the shared resource pool in the case of determining that there are no resources in the exclusive resource pool corresponding to the first thread, it further includes:
[0014] Determine that there are resources in the shared resource pool.
[0015] Optionally, the method further includes:
[0016] When it is determined that there is no resource in the shared resource pool, creating a resource for the first thread;
[0017] Running the first thread by using the obtained resource, including:
[0018] Running the first thread by using the created resource.
[0019] Optionally, the method further includes:
[0020] After the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are less than or equal to a first threshold, releasing the obtained resource to the exclusive resource pool corresponding to the first thread.
[0021] Optionally, the method further includes:
[0022] After the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are greater than the first threshold, locking the shared resource pool and releasing the obtained resource to the shared resource pool; where:
[0023] The resources in the shared resource are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0024] In a second aspect, an embodiment of the present application provides a resource processing apparatus, and the apparatus includes:
[0025] An obtaining unit, configured to obtain a resource from an exclusive resource pool corresponding to a first thread, where the exclusive resource pool corresponding to the first thread is used to provide resources for the first thread;
[0026] A running unit, configured to run the first thread by using the obtained resource.
[0027] Optionally, the apparatus further includes:
[0028] A first determining unit, configured to determine that there is a resource in the exclusive resource pool corresponding to the first thread before obtaining the resource from the exclusive resource pool corresponding to the first thread.
[0029] Optionally, the apparatus further includes:
[0030] A locking unit, configured to lock the shared resource pool and obtain a resource from the shared resource pool when it is determined that there is no resource in the exclusive resource pool corresponding to the first thread; where:
[0031] The resources in the shared resource pool are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0032] Optionally, the apparatus further includes:
[0033] A second determination unit, configured to determine that there are resources in the shared resource pool before locking the shared resource pool and obtaining resources from the shared resource pool.
[0034] Optionally, the apparatus further includes:
[0035] A creation unit, configured to create resources for the first thread when it is determined that there are no resources in the shared resource pool;
[0036] The running unit is configured to:
[0037] Run the first thread by using the created resources.
[0038] Optionally, the apparatus further includes:
[0039] A first release unit, configured to, after the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are less than or equal to a first threshold, release the obtained resources to the exclusive resource pool corresponding to the first thread.
[0040] Optionally, the apparatus further includes:
[0041] A second release unit, configured to, after the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are greater than the first threshold, lock the shared resource pool and release the obtained resources to the shared resource pool; where:
[0042] The resources in the shared resource are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0043] In a third aspect, an embodiment of the present application provides a resource processing apparatus, including a memory, and one or more programs, where one or more programs are stored in the memory and are configured to be executed by one or more processors, and the one or more programs include instructions for performing the following operations:
[0044] Obtain resources from the exclusive resource pool corresponding to the first thread, where the exclusive resource pool corresponding to the first thread is used to provide resources for the first thread;
[0045] Run the first thread by using the obtained resources.
[0046] Optionally, before obtaining a resource from the exclusive resource pool corresponding to the first thread, it further includes:
[0047] Determine that there is a resource in the exclusive resource pool corresponding to the first thread.
[0048] Optionally, the operation further includes:
[0049] In the case where it is determined that there is no resource in the exclusive resource pool corresponding to the first thread, lock the shared resource pool and obtain a resource from the shared resource pool; wherein:
[0050] The resources in the shared resource pool are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0051] Optionally, in the case where it is determined that there is no resource in the exclusive resource pool corresponding to the first thread, before locking the shared resource pool and obtaining a resource from the shared resource pool, it further includes:
[0052] Determine that there is a resource in the shared resource pool.
[0053] Optionally, the operation further includes:
[0054] In the case where it is determined that there is no resource in the shared resource pool, create a resource for the first thread;
[0055] Using the obtained resource to run the first thread includes:
[0056] Using the created resource to run the first thread.
[0057] Optionally, the operation further includes:
[0058] After the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are less than or equal to the first threshold, release the obtained resource to the exclusive resource pool corresponding to the first thread.
[0059] Optionally, the operation further includes:
[0060] After the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are greater than the first threshold, lock the shared resource pool and release the obtained resource to the shared resource pool; wherein:
[0061] The resources in the shared resource are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0062] Fourthly, an embodiment of the present application provides a computer-readable medium, on which instructions are stored, and when executed by one or more processors, cause the device to execute the method described in any item of the above first aspect.
[0063] Compared with the prior art, the embodiment of the present application has the following advantages:
[0064] The embodiment of the present application provides a resource processing method. In this method, unlike in the traditional technology where multiple threads share a shared resource pool, if the first thread needs to run, it can only obtain resources from the shared resource pool when the shared resource pool is not locked by other threads, so as to run the first thread. In the present application, each thread can have a corresponding exclusive resource pool. Taking the first thread as an example, the first thread can have an exclusive resource pool corresponding to the first thread, and the exclusive resource pool corresponding to the first thread is only used to provide resources for the first thread and not for other threads. Exactly because of this, except for the first thread, other threads will not obtain resources from the exclusive resource pool corresponding to the first thread. In other words, the exclusive resource pool corresponding to the first thread will not be locked by other threads like the shared resource pool in the traditional technology. When the first thread needs to run, it can directly obtain resources from the exclusive resource pool corresponding to the first thread, and thus use the obtained resources to run the first thread. It can be seen that the solution of the embodiment of the present application can improve concurrency. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments recorded in the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0066] Figure 1 It is a schematic flowchart of a resource processing method provided by an embodiment of the present application;
[0067] Figure 2 It is a schematic structural diagram of a resource processing device provided by an embodiment of the present application;
[0068] Figure 3 It is a schematic structural diagram of a client provided by an embodiment of the present application;
[0069] Figure 4 It is a schematic structural diagram of a server provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0070] To enable those skilled in the art to better understand the solution of this application, the following will clearly and completely describe the technical solutions in the embodiments of this application with reference to the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of this application.
[0071] The inventors of this application have found through research that pooling technology can be applied to multi-threaded programming. In one example, resources can be pre-created and the created resources can be placed in a shared resource pool. This shared resource pool can be used to provide resources for multiple threads. Currently, when multiple threads all obtain resources from the shared resource pool, at most only one thread can use the resources in the resource pool at the same time. Specifically, when thread 1 needs to obtain resources from the shared resource pool, thread 1 can first lock the shared resource pool (which can also be referred to as locking the shared resource pool), and then obtain resources from the shared resource pool to run thread 1. After thread 1 finishes running, the resources can be released to the shared resource pool, and then the lock on the shared resource pool can be released. When the shared resource pool is in the locked state, other threads cannot obtain resources from the shared resource pool. In other words, if the shared resource pool is locked by thread 1, thread 2 cannot obtain resources from the shared resource pool, and thread 2 must wait until thread 1 releases the lock on the shared resource pool before it can obtain resources from the shared resource pool to run thread 2. Exactly because of this, multiple threads cannot run simultaneously, reducing concurrency.
[0072] To solve the above problems, the embodiments of this application provide a resource processing method and apparatus.
[0073] The following will, with reference to the accompanying drawings, detail various non-limiting embodiments of this application.
[0074] Exemplary method
[0075] See Figure 1 , which is a schematic flowchart of a resource processing method provided by an embodiment of this application.
[0076] The resource processing method provided by the embodiments of this application can be executed by a controller or a processor with data processing capabilities, or can be executed by a device including the aforementioned controller or processor. The embodiments of this application do not specifically limit this. Among them, the device including the controller or processor includes but is not limited to a terminal device and a server.
[0077] In this embodiment, Figure 1 the resource processing method shown, for example, may include the following steps S101 - S102.
[0078] S101: Obtain resources from the exclusive resource pool corresponding to the first thread, where the exclusive resource pool corresponding to the first thread is used to provide resources for the first thread.
[0079] In the embodiments of the present application, an exclusive resource pool can be created for each thread respectively during the initialization stage of the service. Among them, the service can include one or more services, and the services can run in specific threads.
[0080] The first thread is any one of the above-mentioned threads. The exclusive resource pool corresponding to the first thread is only used to provide resources for the first thread and not for other threads. In the embodiments of the present application, the resources in the exclusive resource pool corresponding to the first thread can include, for example, one or more of a thread pool, a memory pool, and a connection pool. Details about the thread pool, the memory pool, and the connection pool are not described here in detail.
[0081] In the embodiments of the present application, when it is necessary to run a service using the first thread, resources can be obtained from the exclusive resource pool corresponding to the first thread.
[0082] S102: Run the first thread by using the obtained resources.
[0083] After obtaining resources from the exclusive resource pool corresponding to the first thread, the first thread can be run by using the resources obtained from the exclusive resource pool corresponding to the first thread, thereby realizing the processing of a certain service.
[0084] From the above description, it can be seen that since the exclusive resource pool corresponding to the first thread is only used to provide resources for the first thread and not for other threads. Therefore, except for the first thread, other threads will not obtain resources from the exclusive resource pool corresponding to the first thread. In other words, the exclusive resource pool corresponding to the first thread will not be locked by other threads like a traditional shared resource pool. When it is necessary to run the first thread, resources can be directly obtained from the exclusive resource pool corresponding to the first thread, and then the first thread can be run by using the obtained resources. Thus, it can be seen that by using the solution of the embodiments of the present application, concurrency can be improved.
[0085] In some scenarios, after the service processing is completed, the resources used for processing the service can be released. During the service processing, there may be multi-thread mutual scheduling, which may cause the resources obtained from the exclusive resource pool of the first thread to be released into the exclusive resource pool of other threads, such as the second thread, resulting in fewer and fewer resources in the exclusive resource pool corresponding to the first thread, and even no resources available. And the resources in the exclusive resource pool corresponding to the second thread are getting more and more.
[0086] For example, in the case of a user login service, there are Thread 1 involved in applying for a link to verify whether the username and password match and Thread 2 for returning the link. When running Thread 1, resources are obtained from the exclusive resource pool corresponding to Thread 1. Since the thread for returning the link is Thread 2, when further returning the link after verifying whether the username and password match, the resources obtained from the exclusive resource pool of Thread 1 will be released to the exclusive resource pool corresponding to Thread 2, resulting in a decrease in the resources in the exclusive resource pool corresponding to Thread 1 and an increase in the resources in the exclusive resource pool corresponding to Thread 2.
[0087] Just because of the above, there may be no resources available in the exclusive resource pool corresponding to the first thread. Therefore, in an example of the embodiment of the present application, before executing the foregoing S101, it is also possible to determine whether there are resources in the exclusive resource pool corresponding to the first thread. If it is determined that there are resources in the exclusive resource pool corresponding to the first thread, then execute the foregoing S101 and subsequent steps, so as to realize running the first thread by using the resources in the exclusive resource pool of the first thread.
[0088] In addition, in order to enable the first thread to run normally when there are no resources in the exclusive resource pool corresponding to the first thread. In the embodiment of the present application, in the initialization stage of the service, in addition to creating an exclusive resource pool for each thread respectively, a shared resource pool can also be created. This shared resource pool is used to provide resources for multiple threads, and the multiple threads include the foregoing first thread. In this way, when there are no resources in the exclusive resource pool corresponding to the first thread, resources can be obtained from this shared resource pool, and the first thread can be run by using the resources obtained from this shared resource pool. Specifically, before obtaining resources from the shared resource pool, the shared resource pool can be locked first, and then resources can be obtained from the shared resource pool.
[0089] In some scenarios of the embodiment of the present application, there are resources in the shared resource pool in the initialization stage of the service. However, as the service runs, there may still be resources or there may be no resources in this shared resource pool. The specific reasons can refer to the description of the resource release part below and will not be analyzed in detail here. Therefore, in an implementation manner of the embodiment of the present application, before locking the shared resource pool, it is also possible to determine whether there are resources in this shared resource pool. If it is determined that there are resources in the shared resource pool, then lock the shared resource pool and obtain resources from this shared resource pool to run the first thread.
[0090] In an example of the embodiment of the present application, if there are no resources in the exclusive resource pool corresponding to the first thread and there are no resources in the shared resource pool either, a new resource can be created for the first thread, and the first thread can be run by using the created resource, so that the first thread can run normally.
[0091] In the embodiments of the present application, after the first thread finishes running, the resources used to run the first thread can be released, that is, the resources obtained mentioned in S102 are released. In some embodiments, considering that if there are resources in the exclusive resource pool corresponding to the first thread, the concurrency can be maximally improved, and it is avoided that when the first thread needs to run, resources need to be obtained from the shared resource pool or re-created. Therefore, after the first thread finishes running, the resources used to run the first thread can be released into the exclusive resource pool corresponding to the first thread.
[0092] It can be understood that the resources used to run the first thread mentioned here can be obtained from the exclusive resource pool corresponding to the first thread, can be obtained from the shared resource pool, or can be temporarily created for the first thread. The embodiments of the present application do not make specific limitations. It is precisely because even if the resources used to run the first thread are obtained from the shared resource pool, the resources can be released into the exclusive resource pool corresponding to the first thread. Therefore, as the service runs, there may be no resources in the shared resource pool.
[0093] In other embodiments, considering that the resources required to run the first thread are generally limited, for example, not exceeding a first threshold. Therefore, when the resources originally included in the exclusive resource pool of the first thread have exceeded the first threshold, it means that there are sufficient resources in the exclusive resource pool corresponding to the first thread to run the first thread. For this situation, in the embodiments of the present application, the resources used to run the first thread can be released into the shared resource pool, so that the shared resource pool can provide resources for other threads, and it can also avoid the problem of low overall resource utilization due to too many resources in the resource pool corresponding to the first thread. Specifically, the shared resource pool can be locked, and the resources used to run the first thread are released into the shared resource pool. After the resources used to run the first thread are released into the shared resource pool, the lock on the shared resource pool can be released.
[0094] In other words, in the embodiments of the present application, after the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are less than or equal to the first threshold, the resources used to run the first thread are released into the exclusive resource pool corresponding to the first thread to maximally improve concurrency. After the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are greater than the first threshold, the shared resource pool is locked, and the obtained resources are released into the shared resource pool, so that the shared resource pool can provide resources for other threads.
[0095] Exemplary device
[0096] Based on the method provided in the above embodiments, an embodiment of the present application further provides a resource processing device, which will be introduced below with reference to the accompanying drawings.
[0097] See Figure 2 , which is a schematic structural diagram of a resource processing device provided by an embodiment of the present application. The device 200 may specifically include, for example: an acquisition unit 201 and a running unit 202.
[0098] The acquisition unit 201 is configured to acquire resources from the exclusive resource pool corresponding to the first thread, and the exclusive resource pool corresponding to the first thread is used to provide resources for the first thread;
[0099] The running unit 202 is configured to run the first thread by using the acquired resources.
[0100] In one implementation, the device further includes:
[0101] The first determination unit is configured to determine that there are resources in the exclusive resource pool corresponding to the first thread before acquiring resources from the exclusive resource pool corresponding to the first thread.
[0102] In one implementation, the device further includes:
[0103] The locking unit is configured to lock the shared resource pool and acquire resources from the shared resource pool when it is determined that there are no resources in the exclusive resource pool corresponding to the first thread; where:
[0104] The resources in the shared resource pool are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0105] In one implementation, the device further includes:
[0106] The second determination unit is configured to determine that there are resources in the shared resource pool before locking the shared resource pool and acquiring resources from the shared resource pool.
[0107] In one implementation, the device further includes:
[0108] The creation unit is configured to create resources for the first thread when it is determined that there are no resources in the shared resource pool;
[0109] The running unit 202 is configured to:
[0110] Run the first thread by using the created resources.
[0111] In one implementation, the device further includes:
[0112] The first release unit is configured to, after the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are less than or equal to a first threshold, release the acquired resources to the exclusive resource pool corresponding to the first thread.
[0113] In one implementation, the apparatus further includes:
[0114] The second release unit is configured to, after the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are greater than the first threshold, lock the shared resource pool and release the acquired resources to the shared resource pool; where:
[0115] The resources in the shared resource are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0116] Since the apparatus 200 is the apparatus corresponding to the method provided in the above method embodiment, the specific implementation of each unit of the apparatus 200 is the same concept as that of the above method embodiment. Therefore, for the specific implementation of each unit of the apparatus 200, reference may be made to the description part of the above method embodiment, which will not be elaborated here.
[0117] The method provided in the embodiments of the present application can be executed by a client or a server. The client and the server that execute the above method are described below respectively.
[0118] Figure 3 A block diagram of a client 300 is shown. For example, the client 300 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0119] Refer to Figure 3 , the client 300 may include one or more of the following components: a processing component 302, a memory 304, a power component 306, a multimedia component 308, an audio component 310, an input / output (I / O) interface 33, a sensor component 314, and a communication component 316.
[0120] The processing component 302 generally controls the overall operation of the client 300, such as operations associated with display, telephone call, data communication, camera operation, and recording operation. The processing element 302 may include one or more processors 320 to execute instructions to complete all or part of the steps of the above method. In addition, the processing component 302 may include one or more modules to facilitate the interaction between the processing component 302 and other components. For example, the processing component 302 may include a multimedia module to facilitate the interaction between the multimedia component 308 and the processing component 302.
[0121] The memory 304 is configured to store various types of data to support the operations of the client 300. Examples of such data include instructions for any applications or methods operating on the client 300, contact data, phone book data, messages, pictures, videos, and the like. The memory 304 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disks, or optical disks.
[0122] The power supply component 306 provides power for various components of the client 300. The power supply component 306 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the client 300.
[0123] The multimedia component 308 includes a screen that provides an output interface between the client 300 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can not only sense the boundaries of the touch or swipe actions but also detect the duration and pressure associated with the touch or swipe operations. In some embodiments, the multimedia component 308 includes a front camera and / or a rear camera. When the client 300 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each of the front camera and the rear camera can be a fixed optical lens system or have a focal length and optical zoom capabilities.
[0124] The audio component 310 is configured to output and / or input audio signals. For example, the audio component 310 includes a microphone (MIC) that is configured to receive external audio signals when the client 300 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals can be further stored in the memory 304 or transmitted via the communication component 316. In some embodiments, the audio component 310 further includes a speaker for outputting audio signals.
[0125] The I / O interface provides an interface between the processing component 302 and a peripheral interface module, which can be a keyboard, a click wheel, buttons, etc. These buttons can include, but are not limited to: a home button, a volume button, a power-on button, and a lock button.
[0126] The sensor assembly 314 includes one or more sensors for providing a status assessment of various aspects for the client 300. For example, the sensor assembly 314 can detect the on / off state of the device 300, the relative positioning of components, such as the display and keypad of the client 300. The sensor assembly 314 can also detect a change in the position of the client 300 or a component of the client 300, the presence or absence of user contact with the client 300, the orientation or acceleration / deceleration of the client 300, and the temperature change of the client 300. The sensor assembly 314 can include proximity sensors configured to detect the presence of nearby objects without any physical contact. The sensor assembly 314 can also include light sensors, such as CMOS or CCD image sensors, for use in imaging applications. In some embodiments, the sensor assembly 314 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0127] The communication component 316 is configured to facilitate communication between the client 300 and other devices in a wired or wireless manner. The client 300 can access a wireless network based on communication standards, such as WiFi, 2G, or 3G, or a combination thereof. In one exemplary embodiment, the communication component 316 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, the communication component 316 further includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0128] In an exemplary embodiment, the client 300 can be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components for performing the following methods:
[0129] Obtain a resource from the exclusive resource pool corresponding to the first thread, where the exclusive resource pool corresponding to the first thread is used to provide resources for the first thread;
[0130] Run the first thread by using the obtained resource.
[0131] In one implementation, before obtaining the resource from the exclusive resource pool corresponding to the first thread, it further includes:
[0132] Determine that there is a resource in the exclusive resource pool corresponding to the first thread.
[0133] In one implementation, the method further includes:
[0134] In the case where it is determined that there is no resource in the exclusive resource pool corresponding to the first thread, lock the shared resource pool and obtain a resource from the shared resource pool; where:
[0135] The resources in the shared resource pool are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0136] In one implementation, before locking the shared resource pool and obtaining a resource from the shared resource pool in the case where it is determined that there is no resource in the exclusive resource pool corresponding to the first thread, it further includes:
[0137] Determine that there is a resource in the shared resource pool.
[0138] In one implementation, the method further includes:
[0139] In the case where it is determined that there is no resource in the shared resource pool, create a resource for the first thread;
[0140] Run the first thread by using the obtained resource, including:
[0141] Run the first thread by using the created resource.
[0142] In one implementation, the method further includes:
[0143] After the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are less than or equal to a first threshold, release the obtained resource to the exclusive resource pool corresponding to the first thread.
[0144] In one implementation, the method further includes:
[0145] After the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are greater than the first threshold, lock the shared resource pool and release the obtained resource to the shared resource pool; where:
[0146] The resources in the shared resource are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0147] Figure 4It is a schematic structural diagram of the server in an embodiment of the present application. The server 400 may vary greatly due to different configurations or performances, and may include one or more central processing units (CPUs) 422 (for example, one or more processors) and a memory 432, and one or more storage media 430 (for example, one or more mass storage devices) for storing application programs 442 or data 444. Among them, the memory 432 and the storage media 430 may be transient storage or persistent storage. The program stored in the storage media 430 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Further, the central processing unit 422 may be configured to communicate with the storage media 430 and execute a series of instruction operations in the storage media 430 on the server 400.
[0148] Further, the central processing unit 422 may execute the following method:
[0149] Obtain resources from the exclusive resource pool corresponding to the first thread, where the exclusive resource pool corresponding to the first thread is used to provide resources for the first thread;
[0150] Use the obtained resources to run the first thread.
[0151] In one implementation, before obtaining resources from the exclusive resource pool corresponding to the first thread, it further includes:
[0152] Determine that there are resources in the exclusive resource pool corresponding to the first thread.
[0153] In one implementation, the method further includes:
[0154] In the case where it is determined that there are no resources in the exclusive resource pool corresponding to the first thread, lock the shared resource pool and obtain resources from the shared resource pool; where:
[0155] The resources in the shared resource pool are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0156] In one implementation, before locking the shared resource pool and obtaining resources from the shared resource pool in the case where it is determined that there are no resources in the exclusive resource pool corresponding to the first thread, it further includes:
[0157] Determine that there are resources in the shared resource pool.
[0158] In one implementation, the method further includes:
[0159] When it is determined that there is no resource in the shared resource pool, create a resource for the first thread;
[0160] Run the first thread by using the obtained resource, including:
[0161] Run the first thread by using the created resource.
[0162] In one implementation, the method further includes:
[0163] After the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are less than or equal to the first threshold, release the obtained resource to the exclusive resource pool corresponding to the first thread.
[0164] In one implementation, the method further includes:
[0165] After the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are greater than the first threshold, lock the shared resource pool and release the obtained resource to the shared resource pool; where:
[0166] The resources in the shared resource are used to provide resources for multiple threads, and the multiple threads include the first thread.
[0167] The server 400 may further include one or more power supplies 426, one or more wired or wireless network interfaces 450, one or more input / output interfaces 456, one or more keyboards 456, and / or one or more operating systems 441, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, and so on.
[0168] The embodiment of the present application also provides a computer-readable medium, on which instructions are stored. When executed by one or more processors, the instructions cause the device to execute the resource processing method provided in the above method embodiment.
[0169] Those skilled in the art will readily conceive of other implementations of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any variations, uses, or adaptations of the present application, which follow the general principles of the present application and include known common knowledge or conventional technical means in the technical field not disclosed in the present disclosure. The specification and embodiments are only to be considered as exemplary, and the true scope and spirit of the present application are pointed out by the following claims.
[0170] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present application is only limited by the appended claims.
[0171] The above are only the preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present application shall be included within the protection scope of the present application.
Claims
1. A resource processing method, characterized in that, The method includes: In the initialization stage of the service, an exclusive resource pool is created for each thread respectively, where the service includes one or more services, and the services run in the threads; Determine that there is a resource in the exclusive resource pool corresponding to the first thread, and obtain the resource from the exclusive resource pool corresponding to the first thread. The exclusive resource pool corresponding to the first thread is only used to provide resources for the first thread. The resources include one or more of a thread pool, a memory pool, and a connection pool. The first thread is any thread in the multi-threads, and each thread in the multi-threads corresponds to an exclusive resource pool; Run the first thread by using the obtained resource; In the case where it is determined that there is no resource in the exclusive resource pool corresponding to the first thread, lock the shared resource pool, obtain a resource from the shared resource pool, and run the first thread by using the resource; In the case where it is determined that there is no resource in the exclusive resource pool corresponding to the first thread and there is no resource in the shared resource pool, create a resource for the first thread, and run the first thread by using the created resource. The resources in the shared resource pool are used to provide resources for multiple threads; After the first thread runs to completion, if the resources included in the exclusive resource pool corresponding to the first thread are less than or equal to a first threshold, release the obtained resource to the exclusive resource pool corresponding to the first thread. The first threshold is determined according to the resources required to run the first thread; If the resources included in the exclusive resource pool corresponding to the first thread are greater than the first threshold, lock the shared resource pool, and release the obtained resource to the shared resource pool.
2. The method according to claim 1, characterized in that Before locking the shared resource pool and obtaining a resource from the shared resource pool in the case where it is determined that there is no resource in the exclusive resource pool corresponding to the first thread, it further includes: Determine that there is a resource in the shared resource pool.
3. A resource processing device, characterized in that, The device includes: An obtaining unit, configured to determine that there is a resource in the exclusive resource pool corresponding to the first thread, and obtain the resource from the exclusive resource pool corresponding to the first thread. The exclusive resource pool corresponding to the first thread is only used to provide resources for the first thread. The resources include one or more of a thread pool, a memory pool, and a connection pool. The first thread is any thread in the multi-threads, and each thread in the multi-threads corresponds to an exclusive resource pool; A running unit, configured to run the first thread by using the obtained resource; A first releasing unit, configured to, after the first thread runs to completion, if the resources included in the exclusive resource pool corresponding to the first thread are less than or equal to a first threshold, release the obtained resource to the exclusive resource pool corresponding to the first thread. The first threshold is determined according to the resources required to run the first thread; A second releasing unit, configured to, after the first thread runs to completion, if the resources included in the exclusive resource pool corresponding to the first thread are greater than the first threshold, lock the shared resource pool, and release the obtained resource to the shared resource pool; A creation unit, configured to create resources for the first thread when it is determined that there are no resources in the exclusive resource pool corresponding to the first thread and there are no resources in the shared resource pool, where the resources in the shared resource pool are used to provide resources for multiple threads; in the initialization stage of the service, create an exclusive resource pool for each thread respectively, where the service includes one or more services, and the services run in the threads; The running unit is configured to: Run the first thread by using the created resources; A locking unit, configured to lock the shared resource pool when it is determined that there are no resources in the exclusive resource pool corresponding to the first thread, obtain resources from the shared resource pool, and run the first thread by using the resources.
4. The device according to claim 3, characterized in that, The device further includes: A second determination unit, configured to determine that there are resources in the shared resource pool before locking the shared resource pool and obtaining resources from the shared resource pool.
5. A resource processing device, characterized in that, It includes a memory and one or more programs, where one or more programs are stored in the memory and are configured to be executed by one or more processors. The one or more programs include instructions for performing the following operations: In the initialization stage of the service, create an exclusive resource pool for each thread respectively, where the service includes one or more services, and the services run in the threads; Determine that there are resources in the exclusive resource pool corresponding to the first thread, and obtain resources from the exclusive resource pool corresponding to the first thread. The exclusive resource pool corresponding to the first thread is only used to provide resources for the first thread, and the resources include one or more of a thread pool, a memory pool, and a connection pool; the first thread is any thread in the multi-threads, and each thread in the multi-threads corresponds to an exclusive resource pool; Run the first thread by using the obtained resources; When it is determined that there are no resources in the exclusive resource pool corresponding to the first thread, lock the shared resource pool and obtain resources from the shared resource pool; When it is determined that there are no resources in the exclusive resource pool corresponding to the first thread and there are no resources in the shared resource pool, create resources for the first thread and run the first thread by using the created resources. The resources in the shared resource pool are used to provide resources for multiple threads; After the first thread finishes running, if the resources included in the exclusive resource pool corresponding to the first thread are less than or equal to a first threshold, release the obtained resources to the exclusive resource pool corresponding to the first thread; If the resources included in the exclusive resource pool corresponding to the first thread are greater than the first threshold, lock the shared resource pool and release the obtained resources to the shared resource pool; Wherein, the first threshold is determined according to the resources required to run the first thread.
6. The device according to claim 5, wherein Before locking the shared resource pool and obtaining resources from the shared resource pool when it is determined that there are no resources in the exclusive resource pool corresponding to the first thread, it further includes: Determine that there are resources in the shared resource pool.
7. A computer-readable medium having instructions stored thereon that, when executed by one or more processors, cause the apparatus to perform the method according to any one of claims 1 to 2.
Citation Information
Patent Citations
Memory management method and device
CN107515785A