CN110109739A - A kind of method for closing and device of multithread application - Google Patents

A kind of method for closing and device of multithread application Download PDF

Info

Publication number
CN110109739A
CN110109739A CN201910339217.8A CN201910339217A CN110109739A CN 110109739 A CN110109739 A CN 110109739A CN 201910339217 A CN201910339217 A CN 201910339217A CN 110109739 A CN110109739 A CN 110109739A
Authority
CN
China
Prior art keywords
thread
numerical value
counter
pool
active
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.)
Pending
Application number
CN201910339217.8A
Other languages
Chinese (zh)
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.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN201910339217.8A priority Critical patent/CN110109739A/en
Publication of CN110109739A publication Critical patent/CN110109739A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/485Task life-cycle, e.g. stopping, restarting, resuming execution

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention provides a kind of method for closing of multithread application and devices, wherein method includes: in the case where needing to close thread pool, whether the numerical value for detecting thread counter is 0, the numerical value of the thread counter indicates the active thread of multithread application, the volume residual that the asynchronous task submitted to thread pool is executed;If the numerical value of the thread counter is 0, shutoff operation is carried out to the thread pool, to close the multithread application.Illustrate that the volume residual that multithread application active thread is executed to the asynchronous task that thread pool is submitted is 0, shutoff operation is carried out to thread pool at this time, the active thread of multithread application can't be killed by force, the asynchronous task not being performed submitted to thread pool would not also cause part work to lose.

Description

A kind of method for closing and device of multithread application
Technical field
The present invention relates to field of computer technology, more particularly to the method for closing and dress of a kind of multithread application It sets.
Background technique
Whole realization is asynchronous at present can be handled using multithreading.It can be with using the application program of multithreading Referred to as multithread application.Multithread application is constructed based on thread pool, in favor of the scheduling and reuse of thread.? In multithread application, active thread may submit new asynchronous task to thread pool in thread pool, these are new asynchronous Task is added in queue, then, distributes thread by thread pool to execute these new asynchronous tasks in queue.
What whether these new asynchronous tasks occurred often being determined by the operational process of specific multithread application, because This does not simultaneously have certainty and predictability.When multithread application needs to close or restart, can not determine whether there is Subsequent asynchronous computing process, i.e., new asynchronous task.If the number of threads of the operation in thread pool converges to before 0 naturally, Thread pool is closed, multithread application can be killed by force, part work is caused to be lost.
Summary of the invention
The method for closing and device for being designed to provide a kind of multithread application of the embodiment of the present invention, to solve In the prior art if the number of threads of the operation in thread pool converges to before 0 naturally, thread pool is closed, can be killed by force multi-thread Journey application program, cause part work lose the technical issues of.Specific technical solution is as follows:
In a first aspect, present invention implementation provides a kind of method for closing of multithread application, comprising:
In the case where needing to close thread pool, whether the numerical value for detecting thread counter is 0, the thread meter The numerical value of number device indicates the active thread of multithread application, the residue that the asynchronous task submitted to thread pool is executed Quantity;
If the numerical value of the thread counter is 0, shutoff operation is carried out to the thread pool, to close the multithreading Application program.
Further, the method also includes:
When receiving the first turn-off request for needing to be closed to multithread application, determination is needed to thread pool It is closed;
Thread is handled by the closing for handling turn-off request, closes the input of the multithread application, and hold The step of whether numerical value of the row detection thread counter is 0.
Further, the method also includes:
If the numerical value of the thread counter is not 0, it is blocked in the closing processing line of the thread counter locked Journey;
When being executed into the thread pool there are active thread, the lock for being blocked in the thread counter is waken up On the closing numerical value that handles thread, and execute detection thread counter the step of whether being 0.
Further, the method also includes:
Determine the numerical value of thread counter.
Further, the numerical value of the determining thread counter, comprising:
The asynchronous task that the active thread of the multithread application is submitted to thread pool is obtained, then described in statistics Current asynchronous task quantity in the active thread of multithread application, the numerical value as thread counter;
The asynchronous task for obtaining the submission of in the thread pool active thread is executed into, then counts described multi-thread Current asynchronous task quantity in the active thread of journey application program, the numerical value as thread counter.
Second aspect, present invention implementation provide a kind of closing device of multithread application, comprising:
First processing module, in the case where needing to close thread pool, detecting the numerical value of thread counter It whether is 0, the numerical value of the thread counter indicates the active thread of multithread application, asynchronous submitted to thread pool The volume residual that business is executed;
Closedown module is controlled, if the numerical value for the thread counter is 0, closing behaviour is carried out to the thread pool Make, to close the multithread application.
Further, described device further include: Second processing module is used for:
When receiving the first turn-off request for needing to be closed to multithread application, determination is needed to thread pool It is closed;
Thread is handled by the closing for handling turn-off request, closes the input of the multithread application, and hold The step of whether numerical value of the detection thread counter described in the row first processing module is 0.
Further, described device further include:
Third processing module is blocked in the thread counter if the numerical value for the thread counter is not 0 The closing processing thread locked;
Fourth processing module, for when being executed into the thread pool there are active thread, wake-up to be blocked in The closing processing thread of the thread counter locked, and execute the detection line described in the first processing module The step of whether numerical value of journey counter is 0.
Further, described device further include:
5th processing module, for determining the numerical value of thread counter.
Further, the 5th processing module, is used for:
The asynchronous task that the active thread of the multithread application is submitted to thread pool is obtained, then described in statistics Current asynchronous task quantity in the active thread of multithread application, the numerical value as thread counter;
The asynchronous task for obtaining the submission of in the thread pool active thread is executed into, then counts described multi-thread Current asynchronous task quantity in the active thread of journey application program, the numerical value as thread counter.
The third aspect, present invention implementation provide a kind of electronic equipment, including processor, communication interface, memory and logical Believe bus, wherein processor, communication interface, memory complete mutual communication by communication bus;
Memory, for storing computer program;
Processor when for executing the program stored on memory, realizes method and step described in first aspect.
Fourth aspect, present invention implementation provide a kind of computer readable storage medium, the computer-readable storage medium Instruction is stored in matter, when run on a computer, so that computer executes any method of above-mentioned first aspect.
5th aspect, present invention implementation additionally provides a kind of computer program product comprising instruction, when it is in computer When upper operation, so that computer executes any method of above-mentioned first aspect.
The method for closing and device of a kind of multithread application provided in an embodiment of the present invention, need to thread pool into In the case that row is closed, whether the numerical value for detecting thread counter is 0, and the numerical value of the thread counter indicates multithreading application The volume residual that program active thread is executed to the asynchronous task that thread pool is submitted, if the numerical value of thread counter is 0, Then to the shutoff operation of thread pool, to close multithread application.
It can be seen that compared to the prior art, when the numerical value of thread counter is 0, illustrating that multithread application is transported The volume residual that line journey is executed to the asynchronous task that thread pool is submitted is 0, carries out shutoff operation to thread pool at this time, The active thread that multithread application can't be killed by force, the asynchronous task not being performed submitted to thread pool, also just not It will cause part work to lose.
Certainly, implement any of the products of the present invention or method it is not absolutely required at the same reach all the above excellent Point.
Detailed description of the invention
In order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, to embodiment or will show below There is required attached drawing in technical description to be briefly described.
Fig. 1 is the first pass schematic diagram of the method for closing of multithread application provided in an embodiment of the present invention;
Fig. 2 is the flow diagram of the numerical value of the determination thread counter of the embodiment of the present invention;
Fig. 3 is the concrete application schematic diagram of the thread counter of the embodiment of the present invention;
Fig. 4 is the second procedure schematic diagram of the method for closing of multithread application provided in an embodiment of the present invention;
Fig. 5 is the structural schematic diagram of the closing device of multithread application provided in an embodiment of the present invention;
Fig. 6 is the structural schematic diagram of electronic equipment provided in an embodiment of the present invention.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention is described.
If before the number of threads for the operation in thread pool of the prior art converges to 0 naturally, closing thread The problem of pond can kill by force multithread application, and part work is caused to be lost, the embodiment of the present invention provides a kind of multithreading application The method for closing and device of program, in the case where needing to close thread pool, detect thread counter numerical value whether It is 0, the asynchronous task that the numerical value of the thread counter indicates that multithread application active thread is submitted to thread pool is held The volume residual that row is completed, if the numerical value of thread counter is 0, to the shutoff operation of thread pool, to close multithreading application Program.In this way when the numerical value of thread counter is 0, it is asynchronous to illustrate that multithread application active thread is submitted to thread pool The volume residual that task is executed is 0, carries out shutoff operation to thread pool at this time, can't kill multithreading application journey by force The active thread of sequence, the asynchronous task not being performed submitted to thread pool would not also cause part work to lose.
The method for closing of multithread application provided in an embodiment of the present invention is introduced first below.
A kind of method for closing of multithread application provided by the embodiment of the present invention is applied to electronic equipment.The electricity Sub- equipment can be with are as follows: desktop computer, portable computer, intelligent mobile terminal, server etc..It is not limited thereto, it is any Electronic equipment of the invention may be implemented, all belong to the scope of protection of the present invention.It specifically can be applied to the behaviour in electronic equipment Make in system, is not limited thereto.
Referring to Fig. 1, Fig. 1 is the first pass signal of the method for closing of multithread application provided in an embodiment of the present invention Figure.The method for closing of multithread application provided by the embodiment of the present invention, may include steps of:
Step 110, in the case where needing to close thread pool, whether the numerical value for detecting thread counter is 0, line The numerical value of journey counter indicates the active thread of multithread application, what the asynchronous task submitted to thread pool was executed Volume residual thens follow the steps 120 if so, the numerical value of i.e. detection thread counter is 0.If not, detecting thread count The numerical value of device is not 0, can be, but not limited to be the step of execution are as follows: return and execute whether the numerical value of detection thread counter is 0 The step of.It in this way can be with the numerical value of constant testing thread counter, until shutoff operation is carried out to thread pool, to close multithreading Application program.
Wherein, thread counter can be used for recording the active thread of multithread application, submit to thread pool different The volume residual that step task is executed.Before this step 110, the method also includes: starting thread counter.Into one It walks, such as in the active thread of multithread application, the remainder that the asynchronous task submitted to thread pool is executed When amount changes, start thread counter, thread counter can be started in time in this way to count to thread pool submission The volume residual that asynchronous task is executed;For another example, when the operating system starts up, start thread counter, it in this way can be with It keeps thread counter to start always, avoids omitting statistics.
The method of the embodiment of the present invention before this step 110, the method also includes: determine need to thread pool carry out It closes, can specifically be realized using following possible implementation:
In one possible implementation, when operating system reaches default closedown condition, it is determined as needing to thread Pond is closed, wherein operating system, which reaches preset closedown condition, can be, but not limited to be preset closing in operating system Condition, for example be the shut-in time point of setting, the shut-in time point of setting can be to be configured according to user demand, can be with It is fixed value.Preset closedown condition is that thread all in operating system executes completion for another example, can be closed naturally in this way Multithread application.Actively determination needs the case where closing to thread pool in this way, and the automation closed may be implemented Journey, and can obtain needing the case where closing thread pool in time.
In alternatively possible implementation, receive user transmission need to close multithread application The first turn-off request when, determination need to close thread pool.In this way in operating system of user operational process, need to close When closing multithread application, the demand of user can satisfy.It is further described below.
It can be realized using following steps in the case where needing to close thread pool in above-mentioned step 110, inspection Whether the numerical value for surveying thread counter is 0:
111st step, when receiving the first turn-off request for needing to be closed to multithread application, determining is needed Thread pool is closed.
Wherein, the first turn-off request is contained in turn-off request, and " first " in the first turn-off request is every in order to distinguish Secondary turn-off request.
Closing for handling turn-off request, which handles thread, can be the thread newly started, be also possible to deposit originally in system And inactive thread, can satisfy the demand of different scenes in this way.Closing for handling turn-off request handles thread It can be the thread being not belonging in thread pool, be to be specifically used to handle used in turn-off request close processing thread.Example Property, the special shutdown hook shutdown hook skill for closing processing thread such as java is used in multithread application Art executes the closing processing of multithread application, and wherein Java is programming technique.It in this way can be independently of the thread of thread pool Controlled and handled, can also to avoid asynchronous task of the task as multithread application that will close processing thread, and Use thread counter.
112nd step handles thread by the closing for handling turn-off request, closes the defeated of multithread application The step of whether numerical value for entering, and executing the detection thread counter is 0.Here the defeated of multithread application is closed Enter is in order to avoid in preparing closing process, multithread application also receives always asynchronous task or request, to make Closing process must be cannot be introduced into.Illustratively, the input of multithread application such as external interface and message queue, stops connecing Receive the request to multithread application.
It can complete to close in the case where the first turn-off request for needing to close multithread application in this way Multithread application.
Multithread application in aforesaid operations system can be the application program for referring to and using multithreading, also, Multithread application can be, but not limited to be webpage web application.Above-mentioned electronic equipment can be intelligent mobile terminal, tool Body can be smart phone, and multithread application also can be, but not limited to the application program of cell phone software, i.e. application program (Application, abbreviation APP).Here APP refers to the third party application of smart phone.
Fortune in order to realize many-sided application of active thread in multithread application, in multithread application Line journey can be according to thread determined by user demand, and these threads are in the state being currently running.Also, line Journey counter, which can be, counts the active thread in multithread application.Example one, if user needs to multi-thread All threads are monitored in journey application program, and complete to close the active thread in all threads, then multi-thread Active thread in journey application program can be the active thread in thread all in multithread application.Corresponding to this Situation, then thread counter can be for recording the active thread in thread all in multithread application.Example two, If user needs to be monitored thread preselected in multithread application, and completes to the fortune in all preselected threads Line journey is closed, then the active thread in multithread application can be in preselected thread in multithread application Active thread.Corresponding to such case, then thread counter can be used for recording preselected thread in multithread application In active thread.Wherein, preselected thread can be from thread all in multithread application, pre-select out strong System, which is closed, will affect the thread that multithread application is closed extremely.For example, preselected thread can be in examination operating system The thread of remaining task.
The task that active thread in above-mentioned multithread application is submitted to thread pool, then referred to as asynchronous task.In order to The active thread that multithread application can be grasped in time, the residue that the asynchronous task submitted to thread pool is executed Quantity, it is therefore desirable to detect the numerical value of thread counter.Error when being written and read in order to avoid the data of thread counter, The embodiment of the invention also includes: all read-write operations of thread counter are synchronized using lock.
In addition, the numerical value in order to determine thread counter, with convenient to use, method in the embodiment of the present invention further include: really Determine the numerical value of thread counter.
The embodiment of the present invention can determine the numerical value of thread counter using following any possible implementation.
In one possible implementation, the first step counts current different in the active thread of multithread application Step task quantity, is determined as the current value of thread counter;
Second step, on the basis of the current value of thread counter, obtain the active thread of multithread application to The asynchronous task that thread pool is submitted then is done atom adding one to the current value of thread counter and is operated, and by atom adding one The current value of thread counter after operation is determined as the numerical value of thread counter, does atom adding to thread counter in this way One operation, may be implemented to have submitted several asynchronous tasks, just add to thread counter several.
Third step, on the basis of the current value of thread counter, the active thread obtained in thread pool is submitted Asynchronous task be executed into, then the atom operation that subtracts one done to the current value of thread counter, and by the atom operation that subtracts one The current value of thread counter afterwards is determined as the numerical value of thread counter, wherein current asynchronous task quantity and current number Value is referred respectively to when demand determines asynchronous task quantity or numerical value, and corresponding asynchronous task quantity or numerical value exist in this way The asynchronous task that an active thread in thread pool is submitted is executed into, illustrates that active thread task terminates to exit.
The Processing Interface after the active thread task in thread pool can be used in above-mentioned third step, such as Java thread pool In afterExecute interface realize.AfterExecutee can be all called after task execution generally in thread pool is complete Interface, wherein thread, which terminates post-process interface afterExecute interface, can refer to java thread pond each work in thread pool Make the interface that can all call automatically after thread, effect be carried out after each worker thread it is some subsequent Round-off work.AfterExecutee interface is used for after each worker thread to thread count in embodiments of the present invention The numerical value of device subtracts one, and it is because this afterExecutee connects that the operation for subtracting one is done using this afterExecutee interface Mouthful can guarantee the operation for subtracting one, corresponding to each worker thread after can execute it is primary, and execute the time must be After worker thread.It, can be to be added up on real-time online journey counter, in real time in this way in above-mentioned possible implementation Obtain the numerical value of thread counter.
It is shown in Figure 2 in alternatively possible implementation, prior to step 110, determine the number of thread counter Value, comprising:
Step 101, the asynchronous task that the active thread of multithread application is submitted to thread pool is obtained, institute is counted State the current asynchronous task quantity in the active thread of multithread application, the numerical value as thread counter.
After the asynchronous task that the active thread that step 101 obtains multithread application is submitted to thread pool, If it is determined that thening follow the steps 110 in the case where needing to close thread pool.The nothing that will not unlimitedly fall into this way The endless loop that method is closed.
Step 102, it obtains the asynchronous task that an active thread in thread pool is submitted to be executed into, then described in statistics Current asynchronous task quantity in the active thread of multithread application, the numerical value as thread counter.
Asynchronous task be thread pool is submitted to by the task in already existing active thread, that is, submit it is asynchronous The active thread (referred to as father's thread 21, as shown in Figure 3) of task is completed before exiting, and asynchronous task would have been completed submission.This The case where inventive embodiments are tracked the submission of active thread using a thread counter and are executed into, whenever one different Step task submits (submission, which refers to, not to be needed actually to bring into operation) to arrive thread pool, just does atom adding to the numerical value n of thread counter One operation;Whenever an active thread terminates just to do the atom operation that subtracts one to the numerical value n of thread counter.Illustratively, such as Fig. 3 Shown, sub thread 1 submits asynchronous task into thread pool, does atom adding one to the numerical value n of thread counter and operates, that is, thread The numerical value n+1 of counter, sub thread 2 submit asynchronous task into thread pool again, do atom again to the numerical value n+1 of thread counter Add an operation, that is, the numerical value n+2 of thread counter.
For father's thread, since the time point of asynchronous task submission is earlier than the time point that father's thread 21 terminates, thread The numerical value of counter, which can first be done after atom adding one operates, is the atom behaviour that subtracts one, that is, the numerical value n+1 of thread counter exists in this way The end of father's thread 21 is exited, asynchronous task is by the presentation stage of execution the active thread for submitting the asynchronous task, thread meter The numerical value of number device is consistently greater than 0.Not only consider to wait the active thread in thread pool when closing multithread application in this way It is executed into, all sub threads of subsequent submission, grandson's thread can also be waited to be executed into automatically, appoint to will not lose What works, and does not need to do any hypothesis to the specific implementation of the asynchronous call relationship, asynchronous mechanism of multithread application.
Step 120, shutoff operation is carried out to thread pool, to close multithread application.
If this step 120 can be, but not limited to include: thread counter numerical value be 0, closing behaviour is carried out to thread pool Make, other cleaning operations is closed, to close multithread application.As long as other cleaning operations can be, but not limited to be that can close The operation for closing multithread application belongs to the protection scope of the embodiment of the present invention.
In the embodiment of the present invention, when the numerical value of thread counter is 0, illustrate multithread application active thread to line The volume residual that the asynchronous task that Cheng Chi is submitted is executed is 0, carries out shutoff operation to thread pool at this time, can't kill by force The active thread for falling multithread application, the asynchronous task not being performed submitted to thread pool, would not also cause part Work is lost.
Shown in Figure 4 in conjunction with shown in Fig. 1, Fig. 2 and Fig. 3, the embodiment of the present invention also provides a kind of multithread application Method for closing, after step 110, the method also includes: if the numerical value of thread counter is not 0, then follow the steps 103。
Step 103, it is blocked in the closing processing thread of thread counter locked.
Wherein, the lock of thread counter can refer to that a lock of thread counter band itself, the lock of thread counter are used In the numerical value of janitor thread counter.The closing processing thread of all numerical value for checking thread counter can be in this thread Locking for counter is blocked;There are active threads to be held after the numerical value change of thread counter, that is, in thread pool Row is completed, and the closing processing thread locked for being blocked in this thread counter can be waken up.It in this way can be according in thread pool With the presence or absence of having the case where active thread is executed into, monitoring thread counter, so that it is determined that being to need wake-up or needs The lock for blocking thread counter, improves the validity of the numerical value change of monitoring thread counter.
Step 104, when being executed into thread pool there are active thread, the lock for being blocked in thread counter is waken up On closing handle thread, and execute numerical value the step of whether being 0 of the detection thread counter.
It is, can return if the numerical value of thread counter is not 0 and continue to execute step 103, until detecting thread The numerical value of counter is 0, thens follow the steps 120 pairs of thread pools and carries out shutoff operation, to close multithread application.In this way when The asynchronous task of all active threads is all executed into when exiting and being submitted without asynchronous task, the numerical value of thread counter It is not further added by and reduces to 0 therewith since the asynchronous task submitted before is executed into.In this way using thread counter come with The submission of active thread and the case where be executed into track multithread application, to judge in multithread application Whether active thread number converges to 0 naturally.
In the embodiment of the present invention, it can use closing processing thread and be blocked in if the numerical value of thread counter is not 0 The closing of thread counter locked handles thread, when being executed into thread pool there are active thread, thread counter Numerical value can do the atom operation that subtracts one, also, wake up the closing processing thread locked for being blocked in thread counter at this time, again Whether the numerical value for detecting thread counter is 0, and according in thread pool, there may be the feelings that active thread is executed in this way Condition, monitoring thread counter improves the validity of monitoring thread counter, and can close multithreading application in time, in turn Shutoff operation system.
The embodiment of the present invention can be applied in various multithread applications, be answered using thread counter tracking multithreading With the submission situation of active thread in program, the opportunity that can be submitted to asynchronous task is required, but not to multithreading application Actual service logic and asynchronous call relationship are not done any it is assumed that guarantee that multithread application is being closed inside program With any work is not lost in restarting process, improve the service quality of multithread application.
It continues with and the closing device of multithread application provided in an embodiment of the present invention is introduced.
Shown in 5, Fig. 5 is the structural schematic diagram of the closing device of the multithread application of the embodiment of the present invention.This The closing device of inventive embodiments offer multithread application, comprising:
First processing module 31, in the case where needing to close thread pool, detecting the number of thread counter Whether value is 0, and the numerical value of the thread counter indicates the active thread of multithread application, is submitted to thread pool asynchronous The volume residual that task is executed;
Closedown module 32 is controlled, if the numerical value for the thread counter is 0, closing behaviour is carried out to the thread pool Make, to close the multithread application.
In the case where needing to close thread pool, whether the numerical value for detecting thread counter is 0, the thread meter The numerical value of number device indicates the remainder that multithread application active thread is executed to the asynchronous task that thread pool is submitted Amount, if the numerical value of thread counter is 0, to the shutoff operation of thread pool, to close multithread application.In this way in thread When the numerical value of counter is 0, illustrate that multithread application active thread is executed into the asynchronous task that thread pool is submitted Volume residual be 0, at this time to thread pool carry out shutoff operation, the active thread of multithread application can't be killed by force, The asynchronous task not being performed submitted to thread pool would not also cause part work to lose.
In one possible implementation, described device further include: Second processing module is used for:
When receiving the first turn-off request for needing to be closed to multithread application, determination is needed to thread pool It is closed;
Thread is handled by the closing for handling turn-off request, closes the input of the multithread application, and hold The step of whether numerical value of the detection thread counter described in the row first processing module is 0.
In one possible implementation, described device further include:
Third processing module is blocked in the thread counter if the numerical value for the thread counter is not 0 The closing processing thread locked;
Fourth processing module, for when being executed into the thread pool there are active thread, wake-up to be blocked in The closing processing thread of the thread counter locked, and execute the detection line described in the first processing module The step of whether numerical value of journey counter is 0.
In one possible implementation, described device further include:
5th processing module, for determining the numerical value of thread counter.
In one possible implementation, the 5th processing module, is used for:
The asynchronous task that the active thread of the multithread application is submitted to thread pool is obtained, then described in statistics Current asynchronous task quantity in the active thread of multithread application, the numerical value as thread counter;
The asynchronous task for obtaining the submission of in the thread pool active thread is executed into, then counts described multi-thread Current asynchronous task quantity in the active thread of journey application program, the numerical value as thread counter.
It is the structural schematic diagram of the electronic equipment of the embodiment of the present invention referring to Fig. 6, Fig. 6.The embodiment of the invention also provides A kind of electronic equipment, including processor 41, communication interface 42, memory 43 and communication bus 44, wherein processor 41, communication Interface 42, memory 43 complete mutual communication by communication bus 44,
Memory 43, for storing computer program;
Processor 41 when for executing the program stored on memory 43, realizes following steps:
In the case where needing to close thread pool, whether the numerical value for detecting thread counter is 0, the thread meter The numerical value of number device indicates the active thread of multithread application, the residue that the asynchronous task submitted to thread pool is executed Quantity;
If the numerical value of the thread counter is 0, shutoff operation is carried out to the thread pool, to close the multithreading Application program.
The communication bus that above-mentioned electronic equipment is mentioned can be Peripheral Component Interconnect standard (Peripheral Component Interconnect, abbreviation PCI) bus or expanding the industrial standard structure (Extended Industry Standard Architecture, abbreviation EISA) bus etc..The communication bus can be divided into address bus, data/address bus, control bus etc.. For convenient for for, be only with a thick line in figure, but for only a bus or a type of bus.
Communication interface is for the communication between above-mentioned electronic equipment and other equipment.
Memory may include random access memory (Random Access Memory, abbreviation RAM), also may include Nonvolatile memory (Non-Volatile Memory, abbreviation NVM), for example, at least a magnetic disk storage.Optionally, it deposits Reservoir can also be that at least one is located remotely from the storage device of aforementioned processor.
Above-mentioned processor can be general processor, including central processing unit (Central Processing Unit, CPU), network processing unit (Network Processor, abbreviation NP) etc.;It can also be digital signal processor (Digital Signal Processing, abbreviation DSP), specific integrated circuit (Application Specific Integrated Circuit, abbreviation ASIC), field programmable gate array (Field-Programmable Gate Array, abbreviation FPGA) or Person other programmable logic device, discrete gate or transistor logic, discrete hardware components.
In another embodiment provided by the invention, a kind of computer readable storage medium is additionally provided, which can It reads to be stored with instruction in storage medium, when run on a computer, so that computer executes any institute in above-described embodiment The method for closing for the multithread application stated.
In another embodiment provided by the invention, a kind of computer program product comprising instruction is additionally provided, when it When running on computers, so that computer executes the closing side of any multithread application in above-described embodiment Method.
For device/electronic equipment/storage medium embodiment/computer program product comprising instruction, due to it It is substantially similar to embodiment of the method, so being described relatively simple, the relevent part can refer to the partial explaination of embodiments of method.
In the above-described embodiments, can come wholly or partly by software, hardware, firmware or any combination thereof real It is existing.When implemented in software, it can entirely or partly realize in the form of a computer program product.The computer program Product includes one or more computer instructions.When loading on computers and executing the computer program instructions, all or It partly generates according to process or function described in the embodiment of the present invention.The computer can be general purpose computer, dedicated meter Calculation machine, computer network or other programmable devices.The computer instruction can store in computer readable storage medium In, or from a computer readable storage medium to the transmission of another computer readable storage medium, for example, the computer Instruction can pass through wired (such as coaxial cable, optical fiber, number from a web-site, computer, server or data center User's line (Digital Subscriber Line, abbreviation DSL) or wireless (such as infrared, wireless, microwave etc.) mode are to another A web-site, computer, server or data center are transmitted.The computer readable storage medium can be computer Any usable medium that can be accessed either includes the data such as one or more usable mediums integrated server, data center Store equipment.The usable medium can be magnetic medium, and (for example, floppy disk, hard disk, tape), optical medium are (for example, high density Digital video disk (Digital Video Disc, abbreviation DVD) or semiconductor medium (such as solid state hard disk (Solid State Disk, abbreviation SSD)) etc..
It should be noted that, in this document, relational terms such as first and second and the like are used merely to a reality Body or operation are distinguished with another entity or operation, are deposited without necessarily requiring or implying between these entities or operation In any actual relationship or order or sequence.Moreover, the terms "include", "comprise" or its any other variant are intended to Non-exclusive inclusion, so that the process, method, article or equipment including a series of elements is not only wanted including those Element, but also including other elements that are not explicitly listed, or further include for this process, method, article or equipment Intrinsic element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that There is also other identical elements in process, method, article or equipment including the element.
Each embodiment in this specification is all made of relevant mode and describes, same and similar portion between each embodiment Dividing may refer to each other, and each embodiment focuses on the differences from other embodiments.Especially for device/ For electronic equipment/storage medium embodiment/computer program product comprising instruction, implement since it is substantially similar to method Example, so being described relatively simple, the relevent part can refer to the partial explaination of embodiments of method.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the scope of the present invention.It is all Any modification, equivalent replacement, improvement and so within the spirit and principles in the present invention, are all contained in protection scope of the present invention It is interior.

Claims (11)

1. a kind of method for closing of multithread application characterized by comprising
In the case where needing to close thread pool, whether the numerical value for detecting thread counter is 0, the thread counter Numerical value indicate the active thread of multithread application, the remainder that is executed of asynchronous task submitted to thread pool Amount;
If the numerical value of the thread counter is 0, shutoff operation is carried out to the thread pool, to close the multithreading application Program.
2. the method as described in claim 1, which is characterized in that the method also includes:
When receiving the first turn-off request for needing to be closed to multithread application, determines and need to carry out thread pool It closes;
Thread is handled by the closing for handling turn-off request, closes the input of the multithread application, and execute institute It states and the step of whether numerical value of the thread counter is 0 is detected.
3. the method as described in claim 1, which is characterized in that the method also includes:
If the numerical value of the thread counter is not 0, it is blocked in the closing processing thread of the thread counter locked;
When being executed into the thread pool there are active thread, wakes up and be blocked in locking for the thread counter The step of closing handles thread, and whether the numerical value for executing the detection thread counter is 0.
4. the method as described in claim 1, which is characterized in that the method also includes:
Determine the numerical value of thread counter.
5. method as claimed in claim 4, which is characterized in that the numerical value of the determining thread counter, comprising:
The asynchronous task that the active thread of the multithread application is submitted to thread pool is obtained, then counts described multi-thread Current asynchronous task quantity in the active thread of journey application program, the numerical value as thread counter;
The asynchronous task for obtaining the submission of in the thread pool active thread is executed into, then counts the multithreading and answer Numerical value with the current asynchronous task quantity in the active thread of program, as thread counter.
6. a kind of closing device of multithread application characterized by comprising
First processing module, in the case where needing to close thread pool, detect thread counter numerical value whether It is 0, the numerical value of the thread counter indicates the active thread of multithread application, the asynchronous task quilt submitted to thread pool Execute the volume residual completed;
Closedown module is controlled, if the numerical value for the thread counter is 0, shutoff operation is carried out to the thread pool, with Close the multithread application.
7. device as claimed in claim 6, which is characterized in that described device further include: Second processing module is used for:
When receiving the first turn-off request for needing to be closed to multithread application, determines and need to carry out thread pool It closes;
Thread is handled by the closing for handling turn-off request, closes the input of the multithread application, and execute institute The step of whether numerical value for stating the detection thread counter described in first processing module is 0.
8. device as claimed in claim 6, which is characterized in that described device further include:
Third processing module is blocked in locking for the thread counter if the numerical value for the thread counter is not 0 Closing handle thread;
Fourth processing module, for when being executed into the thread pool there are active thread, wake-up to be blocked in described The closing processing thread of thread counter locked, and execute the detection thread meter described in the first processing module The step of whether numerical value of number device is 0.
9. device as claimed in claim 6, which is characterized in that described device further include:
5th processing module, for determining the numerical value of thread counter.
10. device as claimed in claim 9, which is characterized in that the 5th processing module is used for:
The asynchronous task that the active thread of the multithread application is submitted to thread pool is obtained, then counts described multi-thread Current asynchronous task quantity in the active thread of journey application program, the numerical value as thread counter;
The asynchronous task for obtaining the submission of in the thread pool active thread is executed into, then counts the multithreading and answer Numerical value with the current asynchronous task quantity in the active thread of program, as thread counter.
11. a kind of electronic equipment, which is characterized in that including processor, communication interface, memory and communication bus, wherein described Processor, the communication interface, the memory complete mutual communication by the communication bus;
The memory, for storing computer program;
The processor when for executing the program stored on the memory, realizes any side claim 1-5 Method step.
CN201910339217.8A 2019-04-25 2019-04-25 A kind of method for closing and device of multithread application Pending CN110109739A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910339217.8A CN110109739A (en) 2019-04-25 2019-04-25 A kind of method for closing and device of multithread application

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910339217.8A CN110109739A (en) 2019-04-25 2019-04-25 A kind of method for closing and device of multithread application

Publications (1)

Publication Number Publication Date
CN110109739A true CN110109739A (en) 2019-08-09

Family

ID=67486694

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910339217.8A Pending CN110109739A (en) 2019-04-25 2019-04-25 A kind of method for closing and device of multithread application

Country Status (1)

Country Link
CN (1) CN110109739A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112181516A (en) * 2020-09-24 2021-01-05 武汉深之度科技有限公司 Application software execution method and computing device

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104462400A (en) * 2014-12-10 2015-03-25 北京奇虎科技有限公司 Method, device and browser client for downloading files in mobile terminals
CN105049243A (en) * 2015-06-30 2015-11-11 上海斐讯数据通信技术有限公司 User MAC positioning method, user MAC positioning system and user MAC positioning server
CN105700938A (en) * 2016-01-15 2016-06-22 浪潮通用软件有限公司 Multithread processing data method and device
CN107220297A (en) * 2017-05-02 2017-09-29 北京大学 The multi-source heterogeneous automated data acquiistion method and system of software-oriented project
CN107357640A (en) * 2017-06-30 2017-11-17 北京奇虎科技有限公司 Request processing method and device, the electronic equipment in multi-thread data storehouse
CN107450978A (en) * 2016-05-31 2017-12-08 北京京东尚科信息技术有限公司 The thread management method and device of distributed system
CN108345499A (en) * 2018-02-01 2018-07-31 平安科技(深圳)有限公司 Unified thread pool processing method, application server and computer readable storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104462400A (en) * 2014-12-10 2015-03-25 北京奇虎科技有限公司 Method, device and browser client for downloading files in mobile terminals
CN105049243A (en) * 2015-06-30 2015-11-11 上海斐讯数据通信技术有限公司 User MAC positioning method, user MAC positioning system and user MAC positioning server
CN105700938A (en) * 2016-01-15 2016-06-22 浪潮通用软件有限公司 Multithread processing data method and device
CN107450978A (en) * 2016-05-31 2017-12-08 北京京东尚科信息技术有限公司 The thread management method and device of distributed system
CN107220297A (en) * 2017-05-02 2017-09-29 北京大学 The multi-source heterogeneous automated data acquiistion method and system of software-oriented project
CN107357640A (en) * 2017-06-30 2017-11-17 北京奇虎科技有限公司 Request processing method and device, the electronic equipment in multi-thread data storehouse
CN108345499A (en) * 2018-02-01 2018-07-31 平安科技(深圳)有限公司 Unified thread pool processing method, application server and computer readable storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王灵生: "ExecutorService 关闭 and 如何判断线程池中任务执行完毕", 《CSDN》 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112181516A (en) * 2020-09-24 2021-01-05 武汉深之度科技有限公司 Application software execution method and computing device

Similar Documents

Publication Publication Date Title
US11157061B2 (en) Processor management via thread status
US11182213B2 (en) Application program management method and device
US8104036B2 (en) Measuring processor use in a hardware multithreading processor environment
US8839271B2 (en) Call stack sampling to obtain information for analyzing idle states in a data processing system
US8763012B2 (en) Scalable, parallel processing of messages while enforcing custom sequencing criteria
US20100017583A1 (en) Call Stack Sampling for a Multi-Processor System
Zhang et al. A comparison of energy bugs for smartphone platforms
US7587718B1 (en) Method and apparatus for enforcing a resource-usage policy in a compute farm
US9720744B2 (en) Performance monitoring of shared processing resources
US10095305B2 (en) Wake lock aware system wide job scheduling for energy efficiency on mobile devices
CN109471711A (en) A kind of method and device of task processing
CN104750536B (en) A kind of method and apparatus realized virtual machine and examined oneself
CN105824709B (en) A kind of critical zone access method and device
CN108446181A (en) The method, apparatus and terminal device access resource constraint
US8001364B2 (en) Dynamically migrating channels
CN109684795A (en) The method, apparatus and electronic equipment of application program anti-debug
CN112181948A (en) Database operation statement processing method and device, electronic equipment and medium
CN110109739A (en) A kind of method for closing and device of multithread application
US11061840B2 (en) Managing network interface controller-generated interrupts
CN113918382A (en) Method, apparatus, device and readable storage medium for resetting
US20160204999A1 (en) Monitoring apparatus and information processing system
CN109697128A (en) A kind of thread maintaining method, device and electronic equipment
CN101617322B (en) Information processing device, information processing method, and program
Bhargava et al. Performance analysis of agent based IPSM
CN101425034A (en) Log recording method and log system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20190809