CN113448585B - Compiling method and device of thread pool, electronic equipment and storage medium - Google Patents

Compiling method and device of thread pool, electronic equipment and storage medium Download PDF

Info

Publication number
CN113448585B
CN113448585B CN202011453407.1A CN202011453407A CN113448585B CN 113448585 B CN113448585 B CN 113448585B CN 202011453407 A CN202011453407 A CN 202011453407A CN 113448585 B CN113448585 B CN 113448585B
Authority
CN
China
Prior art keywords
thread pool
keyword
byte code
code file
custom
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011453407.1A
Other languages
Chinese (zh)
Other versions
CN113448585A (en
Inventor
张帆
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Soyoung Technology Beijing Co Ltd
Original Assignee
Soyoung Technology Beijing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Soyoung Technology Beijing Co Ltd filed Critical Soyoung Technology Beijing Co Ltd
Priority to CN202011453407.1A priority Critical patent/CN113448585B/en
Publication of CN113448585A publication Critical patent/CN113448585A/en
Application granted granted Critical
Publication of CN113448585B publication Critical patent/CN113448585B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/48Indexing scheme relating to G06F9/48
    • G06F2209/481Exception handling
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/48Indexing scheme relating to G06F9/48
    • G06F2209/482Application
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5011Pool
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention discloses a compiling method and device of a thread pool, electronic equipment and a storage medium, wherein the method comprises the following steps: acquiring a byte code file; judging whether the target code in the byte code file hits any keyword according to the keyword in any preset format; under the condition that the byte code file hits any keyword, replacing the thread pool object corresponding to the keyword with a preconfigured custom thread pool object; and compiling the byte code file again according to the self-defined thread pool object to generate an APK installation package with a standard format. According to the compiling method of the thread pool, which is provided by the embodiment of the disclosure, the byte code file can be compiled again according to the self-defined thread pool object, and the APK installation package with the standard format is generated.

Description

Compiling method and device of thread pool, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for compiling a thread pool, an electronic device, and a storage medium.
Background
In the android application development process, a large number of third-party open source frameworks are used to improve development efficiency. Each frame maintains a corresponding thread pool, and a large number of threads are maintained in each thread pool, so that when the application is idle, a large amount of memory resource waste is caused by maintaining the threads all the time. Some third party frames are not in line with the specification in the use of a thread pool, and a large number of threads can be repeatedly created in the running process, so that the resource consumption is serious, the application program always keeps high memory use, the power consumption of the application program is increased, and the mobile phone is heated; even memory overflow and application crash can occur.
Typically, some methods exposed through third party frameworks define thread pools to make the frameworks more specification compliant during operation or use of threads. However, many third party frameworks and third party libraries do not provide functionality that can be directly modified, and therefore it is difficult to standardize the use of the third party frameworks on threads.
The thread is the minimum unit of the system capable of carrying out operation scheduling, is contained in the process, is the actual operation unit in the process, and can be concurrent with a plurality of threads in one process, and each thread carries out different tasks in parallel. At least one process is included in an application.
The thread pool is a container, and the thread pool can create a plurality of threads and store the created threads in the pool. And if the task needs to be executed, the corresponding thread is taken out from the thread pool and executed. After the task is processed, the thread is destroyed according to a preset thread pool usage rule, or the thread is always saved until the execution of the next task is waited. The preconfigured thread pool usage rules may be preconfigured, e.g., the rules may be: the number of tasks that can be executed at most, the waiting rules for tasks, the number of threads that can remain alive at all times, the maximum number of threads, etc.
On the premise of introducing a third party custom thread pool based on the existing thread pool compiling method, the use of a third party framework on threads is difficult to be standardized because of no modification authority of the third party framework and a third party library.
Disclosure of Invention
Based on the above, it is necessary to provide a method, an apparatus, an electronic device and a storage medium for compiling a thread pool, which are necessary to solve the problem that it is difficult to standardize the use of a third party framework on a thread on the premise of introducing a third party custom thread pool based on the existing thread pool compiling method.
In a first aspect, an embodiment of the present application provides a method for compiling a thread pool, where the method includes:
acquiring a byte code file;
judging whether the target code in the byte code file hits any keyword according to the keyword in any preset format;
under the condition that the byte code file hits any keyword, replacing a thread pool object corresponding to the keyword with a preset self-defined thread pool object;
and compiling the byte code file again according to the self-defined thread pool object to generate an APK installation package with a standard format.
In one embodiment, the determining whether the target code in the bytecode file hits any one keyword according to the keyword in any one preset format includes:
reading the target code in the byte code file, wherein the target code comprises a target variable and a target function;
creating a current thread pool expression according to the target variable and/or the target function in the byte code file;
acquiring a keyword pool consisting of keywords in any one preset format;
traversing any keyword in a preset format in the keyword pool according to the function expression and the function name of the current thread pool, judging whether the function expression and the function name of the current thread pool hit the keyword in any preset format in the keyword pool, and determining the keyword as a hit keyword if the function expression and the function name of the current thread pool are consistent with the keyword in any preset format in the keyword pool.
In one embodiment, the method further comprises:
reading any keyword in a preset format in the keyword pool;
and configuring a custom thread pool object with a mapping relation for the thread pool object corresponding to the keyword.
In one embodiment, after the configuring the custom thread pool object having the mapping relation for the thread pool object corresponding to the keyword, the method further includes:
and storing keywords in any preset format, target thread pool code fragments with mapping relation with the keywords and custom thread pool objects with mapping relation with the target thread pool in a list form.
In one embodiment, before the determining whether the target code in the bytecode file hits a keyword in any one of preset formats, the method further includes:
and configuring the attribute of the thread pool to obtain the custom thread pool object.
In one embodiment, the configuring the attribute of the thread pool to obtain the custom thread pool object includes:
configuring the number of core threads in the custom thread pool object; or,
configuring a thread quantity threshold value and a survival time threshold value of non-core threads in the custom thread pool object; or,
configuring a blocking queue for transmitting and storing tasks waiting to be executed in the custom thread pool object; or,
the thread pool and the blocking queue configured in the custom thread pool object are in a saturated state, and are used for processing an abnormal strategy of a corresponding abnormal state; or,
at least one keyword in a preset format and a custom thread pool object with a mapping relation with the thread pool object corresponding to the keyword are configured.
In one embodiment, the recompiling the bytecode file according to the defined thread pool object, generating an APK installation package having a canonical format includes:
according to the defined thread pool object, recompiling the byte code file to obtain a recompiled byte code file;
converting the recompiled byte code file into an executable file;
and generating the APK installation package with a standard format according to the executable file.
In a second aspect, an embodiment of the present application provides a compiling apparatus for a thread pool, where the apparatus includes:
an acquisition unit configured to acquire a bytecode file;
the judging unit is used for judging whether the target code in the byte code file acquired by the acquiring unit hits any keyword according to any keyword in a preset format;
the replacing unit is used for replacing the thread pool object corresponding to any keyword with a preconfigured custom thread pool object under the condition that the judging unit judges that the byte code file hits any keyword;
and the compiling unit is used for compiling the byte code file again according to the self-defined thread pool object replaced by the replacing unit to generate an APK installation package with a standard format.
In a third aspect, embodiments of the present application provide an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor running the computer program to implement the method steps as described above.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium having stored thereon a computer program for execution by a processor to perform the method steps described above.
The technical scheme provided by the embodiment of the application can comprise the following beneficial effects:
in the embodiment of the application, a byte code file is acquired; judging whether the target code in the byte code file hits any keyword according to the keyword in any preset format; under the condition that the byte code file hits any keyword, replacing the thread pool object corresponding to the keyword with a preconfigured custom thread pool object; and compiling the byte code file again according to the self-defined thread pool object to generate an APK installation package with a standard format. According to the compiling method of the thread pool, which is provided by the embodiment of the disclosure, the byte code file can be compiled again according to the self-defined thread pool object, and the APK installation package with the standard format is generated.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
FIG. 1 is a flow diagram of a method for compiling a thread pool according to an embodiment of the present disclosure;
FIG. 2 is a schematic flow chart of creating a custom thread pool object in a method for compiling a thread pool according to an embodiment of the present disclosure;
FIG. 3 is a flow chart of another method for compiling a thread pool according to an embodiment of the present disclosure;
FIG. 4 is a schematic flow chart of a compiling process in a compiling method of a thread pool according to an embodiment of the present disclosure;
FIG. 5 is a schematic flow diagram of a compiling process in another method for compiling a thread pool according to an embodiment of the present disclosure;
FIG. 6 is a schematic diagram of a compiling apparatus for a thread pool according to an embodiment of the present disclosure;
fig. 7 is a schematic diagram of a connection structure of an electronic device according to an embodiment of the present disclosure.
Detailed Description
The following description and the drawings sufficiently illustrate specific embodiments of the invention to enable those skilled in the art to practice them.
It should be understood that the described embodiments are merely some, but not all, embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Alternative embodiments of the present disclosure are described in detail below with reference to the drawings.
As shown in fig. 1, an embodiment of the present disclosure provides a compiling method of a thread pool, which is applied to a server, and specifically includes the following method steps:
s102: acquiring a byte code file;
in the embodiment of the application, the byte code file may be generated by the following method steps, specifically, compiling the project code of the application program and the third party code of at least one third party open source frame to generate the byte code file.
According to the compiling method provided by the embodiment of the application, the byte code files are generated by selecting the third party codes of different third party open source frameworks and compiling the project codes of the application program and the selected third party codes. Because the selected third-party open source frames are different, different byte code files can be generated according to the requirements of different application scenes, and the compiling method of the embodiment of the application can use different application scenes.
S104: judging whether the target code in the byte code file hits any keyword according to the keyword in any preset format; wherein the object code includes an object variable and an object function; therefore, the compiling efficiency is improved, only if whether the target code in the byte code file hits any keyword is judged, the thread pool object corresponding to the keyword is replaced by the pre-configured self-defined thread pool object, otherwise, the code in the current byte code file is the thread pool code with the standard format, and the code in the current byte code file is not required to be compiled again.
In the embodiment of the present application, according to a keyword in any one preset format, determining whether an object code in a bytecode file hits any one keyword includes the following steps:
reading an object code in a byte code file, wherein the object code comprises an object variable and an object function;
creating a current thread pool expression according to a target variable and/or a target function in the byte code file;
acquiring a keyword pool consisting of keywords in any one preset format;
traversing any keyword in a preset format in the keyword pool according to the function expression and the function name of the current thread pool, judging whether the function expression and the function name of the current thread pool hit the keyword in any preset format in the keyword pool, and determining the keyword as the hit keyword if the function expression and the function name of the current thread pool are consistent with the keyword in any preset format in the keyword pool.
In one possible implementation manner, before determining whether the target code in the byte code file contains a keyword in any one of preset formats, the method further includes the following steps:
and configuring the attribute of the thread pool to obtain a custom thread pool object.
In the embodiment of the present application, the keywords in the preset format may be in the following form:
"newFixedThreadPool"、"newFixedThreadPool"、"newWorkStealingPool"、
"newWorkStealingPool"、"newSingleThreadExecutor"、
"newSingleThreadExecutor"、"newCachedThreadPool"、
"newCachedThreadPool"、"newSingleThreadScheduledExecutor"、
"newSingleThreadScheduledExecutor"、"newScheduledThreadPool"、
"newScheduledThreadPool"、"unconfigurableExecutorService"、
"unconfigurableScheduledExecutorService"。
the above only lists the keywords in the common preset format, and may introduce the keywords in other preset formats according to the requirements of different application scenarios, which is not described herein again.
In the embodiment of the present application, in different application scenarios, the attribute of the thread pool may be configured by the following method to obtain a corresponding custom thread pool, which is specifically described as follows:
for example, configuring the number of core threads in a custom thread pool object; in a specific application scenario, the number of core threads in the custom thread pool object may be configured to be 20 threads, namely: even after the 20 threads execute the task, the surviving state is still kept all the time so as to wait for the scheduling of the next task;
for another example, a thread count threshold is configured in a custom thread pool object; in a specific application scenario, the thread number threshold in the custom thread pool object may be configured to be 30 threads, i.e.: when the number of ongoing tasks exceeds the number of core threads, the maximum number of threads that can be additionally created is 10;
furthermore, configuring a survival time threshold of the non-core thread; in a specific application scenario, the survival time threshold of the uncore thread may be configured to be 60 seconds, namely: after more than 60 seconds, the additionally created thread will be destroyed and the system resources reclaimed;
or configuring a blocking queue for transmitting and storing the task waiting to be executed in the custom thread pool object;
or, under the condition that the thread pool and the blocking queue configured in the custom thread pool object are in a saturated state, an abnormal strategy for processing the corresponding abnormal state is used; in a specific application scenario, the anomaly policy is: and under the condition that a thread pool and a blocking queue in the custom thread pool object are in a saturated state, starting a strategy. The policy may be set according to different specific application scenarios, and is not limited herein;
and configuring at least one keyword in a preset format and a custom thread pool object with a mapping relation with the thread pool object corresponding to the keyword.
The above listed common process of configuring the attributes of the thread pool may further configure other attributes of the thread pool according to requirements of different application scenarios, which is not described herein.
Fig. 2 is a schematic flow chart of creating a custom thread pool object in a compiling method of a thread pool according to an embodiment of the disclosure.
As described in fig. 2, the process of creating the custom thread pool object is specifically described as follows:
for example, configuring the number of core threads in a custom thread pool object;
for another example, a thread count threshold in a custom thread pool object, and a non-core thread's time-to-live threshold are configured;
furthermore, configuring a blocking queue for transmitting and storing tasks waiting to be executed in the custom thread pool object;
or, under the condition that the thread pool and the blocking queue configured in the custom thread pool object are in a saturated state, an abnormal strategy for processing the corresponding abnormal state is used;
or configuring at least one keyword in a preset format and a custom thread pool object with a mapping relation with the thread pool object corresponding to the keyword. For a specific description, please refer to the same or similar descriptions as above, and further description is omitted herein.
S106: under the condition that the byte code file hits any keyword, replacing a thread pool object corresponding to the keyword with a preconfigured custom thread pool object, wherein the custom thread pool object is a thread pool code with a standard format; the thread pool object corresponding to the keyword is replaced by the custom thread pool object, and the replaced custom thread pool object is the thread pool code with the standard format, so that the compatibility of the thread pool code for compiling is improved.
In one possible implementation, to simplify the compilation process of the thread pool, custom thread pool objects of thread pool objects corresponding to keywords are pre-configured,
specifically, before judging whether the function expression and the function name of the current thread pool hit any one of keywords in a preset format in the keyword pool, the method further comprises the following steps:
reading any keyword in a preset format in the keyword pool;
and configuring a custom thread pool object with a mapping relation for the thread pool object corresponding to the keyword.
In one possible implementation manner, in order to facilitate searching and querying according to the keywords, the target thread pool code segments corresponding to the keywords and the custom thread pool having a mapping relation with the target thread pool, any one keyword, the target thread pool code segments matched with the keywords and the custom thread pool objects corresponding to the target thread pool are all stored in a one-to-one corresponding list form.
In the embodiment of the application, the target thread pool code segment and the target thread pool are both code segments corresponding to the third party codes of the introduced third party open source framework, or thread pools. The target thread pool is often a thread pool without a canonical format, and programmers often have no editing and modifying rights to the target thread pool, so the compatibility of the target thread pool is often poor.
Specifically, after configuring the custom thread pool object with the mapping relation for the thread pool object corresponding to the keyword, the method further includes the following steps:
storing keywords in any preset format, target thread pool code fragments with mapping relation with the keywords and custom thread pool objects with mapping relation with a target thread pool in a list form; therefore, the corresponding relation among the three can be effectively improved, and finally the compiling efficiency is improved.
S108: compiling the byte code file again according to the self-defined thread pool object to generate an APK installation package with a standard format; because the finally generated APK installation package has a standard format, the compatibility of the APK installation package is improved.
In the embodiment of the application, according to the defined thread pool object, compiling the byte code file again to generate the APK installation package with the standard format comprises the following steps:
according to the defined thread pool object, recompiling the byte code file to obtain a recompiled byte code file;
converting the recompiled byte code file into an executable file;
and generating an APK installation package with a standard format according to the executable file.
In the embodiment of the present application, the byte code file after recompilation may be a class file before compiling and a byte code file after compiling. Under a specific application scenario, the compiling process of the APK is as follows:
1) Compiling an R.java file by using an AAPT;
2) Compiling a java file of AIDL;
3) Compiling the java file into a class file;
4) The compiled class file is made into a dex file, when the class file is packed into the dex file, a preset self-defined thread pool object is matched according to keywords, and the self-defined thread pool object is a thread pool code with a standard format;
5) And compiling the current thread pool according to the custom thread pool object to generate an APK installation package with a standard format.
FIG. 3 is a flow chart illustrating another method for compiling a thread pool according to an embodiment of the present disclosure. The flowchart of fig. 3 is a specific example of a compiling method for a thread pool, and the steps shown in fig. 3 are explained and described as follows:
1) Compiling is started;
2) Compiling item codes of the application program and at least one third party code of a third party open source framework to generate a byte code file;
3) Checking whether the byte code file contains any keyword in a preset format;
4) Under the condition that the byte code file hits any keyword, replacing a thread pool object corresponding to the keyword with a preconfigured custom thread pool object, wherein the custom thread pool object is a thread pool code with a standard format; 5) Compiling the current thread pool according to the defined thread pool object to generate an APK installation package with a standard format;
6) And (5) finishing compiling.
Based on the same or similar description of fig. 3, the foregoing description is bothered, and will not be repeated here.
Fig. 4 is a schematic flow chart of a compiling process in a compiling method of a thread pool according to an embodiment of the disclosure.
The compiling process as shown in fig. 4 is as follows:
1) Compiling is started;
2) Traversing each function in the byte code file;
3) Judging whether the function name contains any preset keyword or not; and if the function name contains any preset keyword, searching a custom thread pool object in the preset configuration according to the keyword, and replacing the thread pool object without the standard format with the custom thread pool object in the preset configuration, wherein the custom thread pool object is a thread pool code with the standard format.
4) And (5) finishing compiling.
Based on the same or similar description of fig. 4, please refer to the foregoing description, and no further description is provided herein.
FIG. 5 is a schematic flow chart of a compiling process in another method for compiling a thread pool according to an embodiment of the disclosure;
based on the same or similar description of fig. 5, please refer to the foregoing description, and no further description is provided herein. The insertion points between the settings and the class and dex files are explained and illustrated herein as follows:
1) Acquiring a class file;
2) Traversing each class file;
3) Checking variables and functions in each class file;
4) Judging whether the creation of the functions and the variables in each class file contains keywords in a preset format, for example, as shown in fig. 5, creating a new thread pool expression "scheduledThreadPoolExecutor" shown in fig. 5 for the thread pool 1, and acquiring a preset custom thread pool object according to the keywords by referring to the keyword pool shown in fig. 5, wherein the keyword pool contains the above-mentioned thread pool expression "scheduledThreadPoolExecutor"; and code replacement is carried out on the codes of the thread pool corresponding to the keywords through the codes of the custom thread pool objects until the replacement is completed. The code of the custom thread pool object has a standard format, and a programmer can modify the thread pool code, so that the compatibility of the thread pool object is improved.
In the embodiment of the disclosure, a byte code file is acquired; judging whether the target code in the byte code file hits any keyword according to the keyword in any preset format; under the condition that the byte code file hits any keyword, replacing the thread pool object corresponding to the keyword with a preconfigured custom thread pool object; and compiling the byte code file again according to the self-defined thread pool object to generate an APK installation package with a standard format. According to the compiling method of the thread pool, which is provided by the embodiment of the disclosure, the byte code file can be compiled again according to the self-defined thread pool object, and the APK installation package with the standard format is generated.
The following is an embodiment of a compiling apparatus for a thread pool according to an embodiment of the present disclosure, which may be used to execute an embodiment of a compiling method for a thread pool according to an embodiment of the present disclosure. For details not disclosed in the embodiment of the compiling apparatus for a thread pool in the embodiment of the disclosure, please refer to the embodiment of the compiling method for the thread pool in the embodiment of the disclosure.
Referring to fig. 6, a schematic structural diagram of a compiling apparatus for a thread pool according to an exemplary embodiment of the present invention is shown. The compiling means of the thread pool may be implemented as all or part of the terminal by software, hardware or a combination of both. The compiling device of the thread pool comprises an acquisition unit 602, a judging unit 604, a replacing unit 606 and a compiling unit 608;
an obtaining unit 602, configured to obtain a byte code file;
a judging unit 604, configured to judge whether the target code in the bytecode file acquired by the acquiring unit 602 hits any one keyword according to any one keyword in a preset format;
a replacing unit 606, configured to replace a thread pool object corresponding to a keyword with a preconfigured custom thread pool object when the judging unit 604 judges that the bytecode file hits any one keyword;
the compiling unit 608 is configured to recompile the bytecode file according to the custom thread pool object replaced by the replacing unit 606, and generate an APK installation package with a canonical format.
Optionally, the judging unit 604 is specifically configured to:
reading an object code in a byte code file, wherein the object code comprises an object variable and an object function;
creating a current thread pool expression according to a target variable and a target function in the byte code file;
acquiring a keyword pool consisting of keywords in any one preset format;
traversing any keyword in a preset format in the keyword pool according to the function expression and the function name of the current thread pool, judging whether the function expression and the function name of the current thread pool hit the keyword in any preset format in the keyword pool, and determining the keyword as the hit keyword if the function expression and the function name of the current thread pool are consistent with the keyword in any preset format in the keyword pool.
Optionally, the apparatus further includes:
a reading unit (not shown in fig. 6) for reading any one of the keywords in the preset format in the keyword pool determined by the determining unit 604;
a configuration unit (not shown in fig. 6) for configuring a custom thread pool object having a mapping relationship for the thread pool object corresponding to the keyword read by the reading unit.
Optionally, the apparatus further includes:
a storage unit (not shown in fig. 6) for storing, after the configuration unit configures the custom thread pool object having a mapping relationship for the thread pool object corresponding to the keyword read by the reading unit, keywords in any one preset format, the target thread pool code fragment having a mapping relationship with the keywords, and the custom thread pool object having a mapping relationship with the target thread pool in list form.
Optionally, before the determining unit 604 determines whether the target code in the bytecode file hits a keyword in any one of the preset formats, the configuration unit is further specifically configured to: and configuring the attribute of the thread pool to obtain a custom thread pool object.
Optionally, the configuration unit is specifically configured to:
configuring the number of core threads in the custom thread pool object; or,
configuring a thread quantity threshold value and a survival time threshold value of non-core threads in a custom thread pool object; or alternatively
Configuring a blocking queue for transmitting and storing tasks waiting to be executed in a custom thread pool object; or,
under the condition that a thread pool and a blocking queue configured in the custom thread pool object are in a saturated state, an abnormal strategy for processing a corresponding abnormal state is used; or,
at least one keyword in a preset format and a custom thread pool object with a mapping relation with the thread pool object corresponding to the keyword are configured.
Optionally, the compiling unit 608 is specifically configured to:
according to the defined thread pool object, compiling the byte code file again to obtain a recompiled byte code file;
converting the recompiled byte code file into an executable file;
and generating an APK installation package with a standard format according to the executable file.
It should be noted that, when the compiling apparatus for a thread pool provided in the foregoing embodiment executes the compiling method for a thread pool, only the division of the foregoing functional units is used as an example, in practical application, the foregoing functional allocation may be completed by different functional units according to needs, that is, the internal structure of the device is divided into different functional units, so as to complete all or part of the functions described above. In addition, the compiling device of the thread pool and the compiling method embodiment of the thread pool provided in the foregoing embodiments belong to the same concept, and the implementation process is detailed in the compiling method embodiment of the thread pool, which is not described herein again.
In an embodiment of the present disclosure, the obtaining unit is configured to obtain a bytecode file; the judging unit is used for judging whether the target code in the byte code file acquired by the acquiring unit hits any keyword according to the keyword in any preset format; under the condition that the judging unit judges that the byte code file hits any keyword, replacing a thread pool object corresponding to the keyword with a preset self-defined thread pool object; and the compiling unit re-compiles the byte code file according to the self-defined thread pool object replaced by the replacing unit to generate an APK installation package with a standard format. According to the compiling method of the thread pool, which is provided by the embodiment of the disclosure, the byte code file can be compiled again according to the self-defined thread pool object, and the APK installation package with the standard format is generated.
As shown in fig. 7, the present embodiment provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor running the computer program to implement the method steps as described above.
The disclosed embodiments provide a storage medium storing computer readable instructions having a computer program stored thereon, the program being executed by a processor to perform the method steps described above.
Referring now to fig. 7, a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure is shown. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and the like, and stationary terminals such as digital TVs, desktop computers, and the like. The electronic device shown in fig. 7 is merely an example and should not be construed to limit the functionality and scope of use of the disclosed embodiments.
As shown in fig. 7, the electronic device may include a processing means (e.g., a central processing unit, a graphics processor, etc.) 701, which may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 702 or a program loaded from a storage means 708 into a Random Access Memory (RAM) 703. In the RAM703, various programs and data necessary for the operation of the electronic apparatus are also stored. The processing device 701, the ROM702, and the RAM703 are connected to each other through a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
In general, the following devices may be connected to the I/O interface 705: input devices 706 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, and the like; an output device 707 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 708 including, for example, magnetic tape, hard disk, etc.; and a communication device 709. The communication means 709 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. While fig. 7 shows an electronic device having various means, it is to be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may be implemented or provided instead.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network via communication device 709, or installed from storage 708, or installed from ROM 702. The above-described functions defined in the methods of the embodiments of the present disclosure are performed when the computer program is executed by the processing device 701.
It should be noted that the computer readable medium described in the present disclosure may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present disclosure, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, fiber optic cables, RF (radio frequency), and the like, or any suitable combination of the foregoing.
The computer readable medium may be contained in the electronic device; or may exist alone without being incorporated into the electronic device.
Computer program code for carrying out operations of the present disclosure may be written in one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments of the present disclosure may be implemented by means of software, or may be implemented by means of hardware. Wherein the names of the units do not constitute a limitation of the units themselves in some cases.

Claims (9)

1. A method of compiling a thread pool, the method comprising:
acquiring a byte code file, wherein the byte code file is generated by compiling project codes of an application program and third party codes of at least one third party open source frame;
judging whether the target code in the byte code file hits any keyword according to the keyword in any preset format;
under the condition that the byte code file hits any keyword, replacing a thread pool object corresponding to the keyword with a preset self-defined thread pool object;
compiling the byte code file again according to the self-defined thread pool object to generate an APK installation package with a standard format;
the step of judging whether the target code in the byte code file hits any one keyword according to the keyword in any one preset format comprises the following steps:
reading the target code in the byte code file, wherein the target code comprises a target variable and a target function;
creating a current thread pool expression according to the target variable and/or the target function in the byte code file;
acquiring a keyword pool consisting of keywords in any one preset format;
traversing any keyword in a preset format in the keyword pool according to the function expression and the function name of the current thread pool, judging whether the function expression and the function name of the current thread pool hit the keyword in any preset format in the keyword pool, and determining the keyword as a hit keyword if the function expression and the function name of the current thread pool are consistent with the keyword in any preset format in the keyword pool.
2. The method according to claim 1, wherein the method further comprises:
reading any keyword in a preset format in the keyword pool;
and configuring a custom thread pool object with a mapping relation for the thread pool object corresponding to the keyword.
3. The method of claim 2, wherein after said configuring a custom thread pool object having a mapping relationship for a thread pool object corresponding to said keyword, the method further comprises:
and storing keywords in any preset format, target thread pool code fragments with mapping relation with the keywords and custom thread pool objects with mapping relation with the target thread pool in a list form.
4. The method of claim 2, wherein prior to said determining whether the object code in the bytecode file hits any of the keywords in the preset format, the method further comprises:
and configuring the attribute of the thread pool to obtain the custom thread pool object.
5. The method of claim 4, wherein configuring the attributes of the thread pool to obtain the custom thread pool object comprises:
configuring the number of core threads in the custom thread pool object; or,
configuring a thread quantity threshold value and a survival time threshold value of non-core threads in the custom thread pool object; or,
configuring a blocking queue for transmitting and storing tasks waiting to be executed in the custom thread pool object; or,
the thread pool and the blocking queue configured in the custom thread pool object are in a saturated state, and are used for processing an abnormal strategy of a corresponding abnormal state; or,
at least one keyword in a preset format and a custom thread pool object with a mapping relation with the thread pool object corresponding to the keyword are configured.
6. The method of claim 1, wherein recompiling the bytecode file according to the custom thread pool object, generating an APK installation package having a canonical format comprises:
according to the custom thread pool object, recompiling the byte code file to obtain a recompiled byte code file;
converting the recompiled byte code file into an executable file;
and generating the APK installation package with a standard format according to the executable file.
7. A compilation apparatus for a thread pool, the apparatus comprising:
the system comprises an acquisition unit, a storage unit and a storage unit, wherein the acquisition unit is used for acquiring a byte code file, and the byte code file is generated by compiling project codes of an application program and third party codes of at least one third party open source frame;
the judging unit is used for judging whether the target code in the byte code file acquired by the acquiring unit hits any keyword according to any keyword in a preset format;
the replacing unit is used for replacing the thread pool object corresponding to any keyword with a preconfigured custom thread pool object under the condition that the judging unit judges that the byte code file hits any keyword;
the compiling unit is used for compiling the byte code file again according to the self-defined thread pool object replaced by the replacing unit to generate an APK installation package with a standard format;
the judging unit is specifically configured to:
reading an object code in a byte code file, wherein the object code comprises an object variable and an object function;
creating a current thread pool expression according to a target variable and a target function in the byte code file;
acquiring a keyword pool consisting of keywords in any one preset format;
traversing any keyword in a preset format in the keyword pool according to the function expression and the function name of the current thread pool, judging whether the function expression and the function name of the current thread pool hit the keyword in any preset format in the keyword pool, and determining the keyword as the hit keyword if the function expression and the function name of the current thread pool are consistent with the keyword in any preset format in the keyword pool.
8. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor runs the computer program to implement the method of any one of claims 1-6.
9. A computer readable storage medium having stored thereon a computer program, wherein the program is executed by a processor to implement the method of any of claims 1-6.
CN202011453407.1A 2020-12-11 2020-12-11 Compiling method and device of thread pool, electronic equipment and storage medium Active CN113448585B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011453407.1A CN113448585B (en) 2020-12-11 2020-12-11 Compiling method and device of thread pool, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011453407.1A CN113448585B (en) 2020-12-11 2020-12-11 Compiling method and device of thread pool, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113448585A CN113448585A (en) 2021-09-28
CN113448585B true CN113448585B (en) 2024-01-16

Family

ID=77808628

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011453407.1A Active CN113448585B (en) 2020-12-11 2020-12-11 Compiling method and device of thread pool, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113448585B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115981962B (en) * 2022-12-30 2024-03-12 北京基调网络股份有限公司 Thread pool monitoring method and device, electronic equipment and storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20090006572A (en) * 2007-07-12 2009-01-15 삼성전자주식회사 Apparatus and method for managing thread pool
CN108595187A (en) * 2018-03-27 2018-09-28 北京美好人生伙伴信息技术有限公司 Method, device and the storage medium of Android installation kit integrated software development kit
CN108984177A (en) * 2018-06-21 2018-12-11 中国铁塔股份有限公司 A kind of data processing method and system
CN109445880A (en) * 2018-10-23 2019-03-08 数贸科技(北京)有限公司 Transmission method, device and the electronic equipment of cross-thread calls chain context
CN110134400A (en) * 2019-04-02 2019-08-16 北京奇艺世纪科技有限公司 Data capture method, device, electronic equipment and computer readable storage medium
CN110262841A (en) * 2018-03-07 2019-09-20 北京京东尚科信息技术有限公司 The method and apparatus that a kind of pair of bytecode is enhanced
CN110609687A (en) * 2019-04-12 2019-12-24 北京字节跳动网络技术有限公司 Compiling method, device, electronic equipment and storage medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7469403B2 (en) * 2001-04-19 2008-12-23 International Business Machines Corporation Static detection of a datarace condition for multithreaded object-oriented applications
US9038041B2 (en) * 2006-12-04 2015-05-19 Tibco Software, Inc. Stream processor with compiled programs

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20090006572A (en) * 2007-07-12 2009-01-15 삼성전자주식회사 Apparatus and method for managing thread pool
CN110262841A (en) * 2018-03-07 2019-09-20 北京京东尚科信息技术有限公司 The method and apparatus that a kind of pair of bytecode is enhanced
CN108595187A (en) * 2018-03-27 2018-09-28 北京美好人生伙伴信息技术有限公司 Method, device and the storage medium of Android installation kit integrated software development kit
CN108984177A (en) * 2018-06-21 2018-12-11 中国铁塔股份有限公司 A kind of data processing method and system
CN109445880A (en) * 2018-10-23 2019-03-08 数贸科技(北京)有限公司 Transmission method, device and the electronic equipment of cross-thread calls chain context
CN110134400A (en) * 2019-04-02 2019-08-16 北京奇艺世纪科技有限公司 Data capture method, device, electronic equipment and computer readable storage medium
CN110609687A (en) * 2019-04-12 2019-12-24 北京字节跳动网络技术有限公司 Compiling method, device, electronic equipment and storage medium

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
A comparative study of parallel and distributed Java projects for heterogeneous systems;J.AI-Jaroodi;《Proceedings 16th International Parallel and Distributed Porocessing Symposium》;第8页 *
基于Java应用的自顶向下性能优化方法;唐科;《软件导刊》(第2018年11期期);第45-48页 *
基于字节码动态生成的Java并行框架的建立与优化;辛锐;《中国优秀硕士学位论文全文数据库 信息科技辑》(第2015年07期);I138-72 *

Also Published As

Publication number Publication date
CN113448585A (en) 2021-09-28

Similar Documents

Publication Publication Date Title
CN111367516B (en) Application interface generation method and device and electronic equipment
CN112395253B (en) Index file generation method, terminal device, electronic device and medium
CN111309375B (en) Method, device, medium and electronic equipment for generating remote procedure call toolkit
CN111740948B (en) Data packet issuing method, dynamic updating method, device, equipment and medium
CN110609687A (en) Compiling method, device, electronic equipment and storage medium
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN110489162B (en) Method, device, medium and equipment for simplifying installation package SO (storage and retrieval) file
CN112631590A (en) Component library generation method and device, electronic equipment and computer readable medium
CN113407165B (en) SDK generation and self-upgrade method, device, readable medium and equipment
CN112416303B (en) Software development kit hot repair method and device and electronic equipment
CN113448585B (en) Compiling method and device of thread pool, electronic equipment and storage medium
CN111414308B (en) Application package processing method and application running method and device
CN111352644A (en) Applet updating method, device, server and storage medium
CN106778270B (en) Malicious application detection method and system
CN111625326B (en) Task pipeline execution method and device and electronic equipment
CN111796865B (en) Byte code file modification method, device, terminal equipment and medium
CN111240738B (en) File processing method, device, equipment and medium
CN110489180B (en) Buried point reporting method, device, medium and electronic equipment
CN111309323B (en) Parameter initialization method and device and electronic equipment
CN111310175A (en) iOS application safety monitoring and protecting method and device based on plug-in
CN109933334B (en) Program execution method, device, equipment and medium
CN112559394B (en) System library access method and device and electronic equipment
CN113553040B (en) Registration realization method, device, equipment and medium for visible and spoken identification function
CN112015394B (en) Android function module development method and device, computer system and storage medium
CN112688863B (en) Gateway data processing method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant