CN106681809A - Lock-based thread management method and lock-based thread management device - Google Patents

Lock-based thread management method and lock-based thread management device Download PDF

Info

Publication number
CN106681809A
CN106681809A CN201611100549.3A CN201611100549A CN106681809A CN 106681809 A CN106681809 A CN 106681809A CN 201611100549 A CN201611100549 A CN 201611100549A CN 106681809 A CN106681809 A CN 106681809A
Authority
CN
China
Prior art keywords
lock
lock resource
thread management
resource
threshold value
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
CN201611100549.3A
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.)
Shanghai Feixun Data Communication Technology Co Ltd
Original Assignee
Shanghai Feixun Data Communication 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 Shanghai Feixun Data Communication Technology Co Ltd filed Critical Shanghai Feixun Data Communication Technology Co Ltd
Priority to CN201611100549.3A priority Critical patent/CN106681809A/en
Publication of CN106681809A publication Critical patent/CN106681809A/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
    • 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/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources

Abstract

The invention discloses a lock-based thread management method. The lock-based thread management method includes: S100, acquiring number information of distributed lock resources when receiving lock resource acquisition requests; S200, judging whether the number of the distributed lock resources is larger than a preset threshold value or not according to the number information of the distributed lock resources, if yes, repeatedly executing the step S200, and if not, executing the next step; S300, receiving the lock resource acquisition requests, and distributing lock resources to threads initiating the lock resource acquisition requests. By the lock-based thread management method and the lock-based thread management device, the lock resources can be monitored, and the problem of excessive system processing resource occupation caused by continuous monitoring of lock behaviors can be avoided.

Description

A kind of thread management method and device based on lock
Technical field
The present invention relates to field, more particularly to a kind of thread management method and device based on lock.
Background technology
Java server program will typically provide the service ability of high concurrent, and multithreading causes the concurrency for servicing to carry significantly Rise.In order to solve the problems, such as resource access conflict, lock be it is a kind of commonly with technology, i.e., multiple threads access one simultaneously During resource, because there is particularity in some resources, once can only be by a thread accesses, such as:Write behaviour is carried out to file Make, if multiple threads write the problem that file content can be caused chaotic simultaneously.Therefore, write operation is carried out to file, it is necessary to One lock of setting, only getting the thread of lock could write to file.In reality, there are many places to be required for using To lock.
Now lock is the technology point of comparative maturity in Java, but nonetheless, during actual use, is still held very much Easily go wrong, such as certain thread takes always certain resource, does not discharge always, other threads can always wait obstruction. Because the request of client is constantly produced, thread also can accordingly increase, if resource cannot discharge always, service end meeting quickly Substantial amounts of thread is produced, so that the resource exhaustion of server, loses service ability.
The content of the invention
To solve above-mentioned technical problem, the present invention provides a kind of thread management method based on lock and device, can be to lock Resource is monitored, and caused by can avoiding the occurrence of because continuously carrying out lock behavior monitoring asking for system processing resources is excessively taken Topic.
The technical scheme that the present invention is provided is as follows:
The invention discloses a kind of thread management method based on lock, including step:S100, when receive obtain lock resource During request, acquisition distributes lock resource quantity information;Distribute lock resource quantity information described in S200, basis and judge allocated Whether lock resource quantity is more than predetermined threshold value;If so, step S200 is repeated;Otherwise perform next step;S300, acceptance are described Lock request is obtained, is to initiate to obtain the thread distribution lock resource of lock resource request.
It is further preferred that also including step before step S100:S010, the setting predetermined threshold value;It is described pre- If threshold value is the maximum lock resource quantity that user is arranged;S020, setting preset duration;The preset duration is what user was arranged The most long lock resource occupied time.
Invention additionally discloses another kind of thread management method based on lock, including step:S100, when receive obtain lock money When source is asked, acquisition distributes lock resource quantity information;Distribute lock resource quantity information described in S200, basis to judge to distribute Lock resource quantity whether be more than predetermined threshold value;If so, step S200 is repeated;Otherwise perform next step;S300, receive institute Acquisition lock request is stated, is to initiate to obtain the thread distribution lock resource of lock resource request;S400, the shape for monitoring allocated lock resource State;S500, judge whether allocated lock resource occupied time exceedes the preset duration;If so, then forcible aborting is locked Resource.
It is further preferred that also including step:S600, when have lock resource discharge when, update described in distributed lock number of resources Amount information.
Invention additionally discloses a kind of thread management device based on lock, including:Acquisition module, for working as acquisition lock is received During resource request, acquisition distributes lock resource quantity information;Quantity judge module, for having distributed lock resource quantity according to Whether information judges allocated lock resource quantity more than predetermined threshold value;Distribute module, for when allocated lock resource quantity During more than predetermined threshold value, receive the thread distribution lock resource for obtaining lock resource request, being initiation obtains lock resource request.
It is further preferred that also including:Setup module, for arranging the predetermined threshold value;And setting preset duration;Institute State the maximum lock resource quantity that predetermined threshold value is that user is arranged;The preset duration is the most long lock resource quilt that user is arranged The time of occupancy.
Invention additionally discloses a kind of thread management device based on lock, including:Acquisition module, for working as acquisition lock is received During resource request, acquisition distributes lock resource quantity information;Quantity judge module, for having distributed lock resource quantity according to Whether information judges allocated lock resource quantity more than predetermined threshold value;Distribute module, for when allocated lock resource quantity During more than predetermined threshold value, receive the thread distribution lock resource for obtaining lock resource request, being initiation obtains lock resource request;Prison Control module, for monitoring the state of allocated lock resource;Duration judge module, it is occupied for judging allocated lock resource Time whether exceed the preset duration;Release module, judges that the allocated lock resource occupied time exceedes for working as During the preset duration, forcible aborting lock resource.
It is further preferred that also including:Update module, for when there is lock resource to discharge, distributing lock money described in renewal Source quantity information.
Compared with prior art, all of thread lock is obtained using factory mode in the present invention, by an object unification point With lock resource, so public to be assigned with how many locks, each lock is consumed and how long can be monitored.The present invention to distributing Lock quantity arrange predetermined threshold value, if the quantity for monitoring currently allocated lock has reached predetermined threshold value, no longer receive New request, excessively takes the problem of system processing resources, together caused by can avoiding the occurrence of because continuously carrying out lock behavior monitoring When, when the time that certain thread takes lock resource reaches preset duration, meeting forcible aborting lock resource of the invention reduces lock money The waste in source, is system reasonable arrangement resource.
Description of the drawings
Below by clearly understandable mode, preferred implementation is described with reference to the drawings, the present invention is given furtherly It is bright.
Fig. 1 is a kind of key step schematic diagram of the thread management method based on lock of the present invention;
The step of Fig. 2 is a kind of another specific embodiment of thread management method based on lock of present invention schematic diagram;
Fig. 3 is a kind of flow chart of the thread management method based on lock of the present invention;
Fig. 4 is a kind of main composition schematic diagram of the thread management device based on lock of the present invention;
Fig. 5 is that the present invention is a kind of is fully composed schematic diagram based on the thread management device locked.
Drawing reference numeral explanation:
10th, acquisition module, 20, quantity judge module, 30, distribute module, 40, setup module, 50, monitoring module, 60, when Long judge module, 70, release module, 80, update module.
Specific embodiment
In order to be illustrated more clearly that the embodiment of the present invention or technical scheme of the prior art, below by control description of the drawings The specific embodiment of the present invention.It should be evident that drawings in the following description are only some embodiments of the present invention, for For those of ordinary skill in the art, on the premise of not paying creative work, can be obtaining other according to these accompanying drawings Accompanying drawing, and obtain other embodiments.
To make simplified form, part related to the present invention is only schematically show in each figure, they are not represented Its practical structures as product.In addition, so that simplified form is readily appreciated, with identical structure or function in some figures Part, only symbolically depicts one of those, or has only marked one of those.Herein, " one " is not only represented " only this ", it is also possible to represent the situation of " more than one ".
Fig. 1 is a kind of key step schematic diagram of the thread management method based on lock of the present invention, as shown in figure 1, a kind of base In the thread management method of lock, including step:S100, when receive obtain lock resource request when, acquisition distributed lock number of resources Amount information;Whether distribute lock resource quantity information described in S200, basis judges allocated lock resource quantity more than default threshold Value;If so, step S200 is repeated;Otherwise perform next step;S300, the acceptance lock that obtains are asked, and are to initiate acquisition lock The thread distribution lock resource of resource request.
All of thread lock is obtained using factory mode in the present invention, so public by an object unified distribution lock resource How many locks are assigned with altogether, and each lock is consumed and how long can be monitored.The present invention arranges pre- to allocated lock quantity If threshold value, if the quantity for monitoring currently allocated lock has reached predetermined threshold value, no longer receive new request, can keep away The problem for exempting to occur excessively taking system processing resources caused by because continuously carrying out lock behavior monitoring.
Preferably, step is also included before step S100:S010, the setting predetermined threshold value;The predetermined threshold value For the maximum lock resource quantity that user is arranged;S020, setting preset duration;The preset duration is the most long of user's setting The lock resource occupied time.
Specifically, the step of Fig. 2 is a kind of another specific embodiment of thread management method based on lock of the present invention is shown It is intended to.As shown in Fig. 2 another kind of thread management method based on lock, including step:S100, when receive obtain lock resource please When asking, acquisition distributes lock resource quantity information;Distribute lock resource quantity information described in S200, basis and judge allocated lock Whether resource quantity is more than predetermined threshold value;If so, step S200 is repeated;Otherwise perform next step;Obtain described in S300, acceptance Lock request is taken, is to initiate to obtain the thread distribution lock resource of lock resource request;S400, the state for monitoring allocated lock resource; S500, judge whether allocated lock resource occupied time exceedes the preset duration;If so, then forcible aborting lock is provided Source.
Preferably, also including step:S600, when there is lock resource to discharge, update it is described distribute lock resource quantity information.
Fig. 3 is a kind of flow chart of the thread management method based on lock of the present invention.As shown in figure 3, the workflow of the present invention Journey is specific as follows:
300th, start.
310th, user arranges predetermined threshold value and preset duration.
320th, receive and obtain lock resource request.
Whether the 330th, distribute lock resource quantity information according to judges allocated lock resource quantity more than default threshold Value;If so, step 330 is repeated;Otherwise, next step is performed.
340th, the thread distribution lock resource for obtaining lock request, being initiation obtains lock resource request is received.
350th, the state of allocated lock resource is monitored.
360th, judge whether the allocated lock resource occupied time exceedes the preset duration;If so, execution step 370;Otherwise, execution step 380.
370th, forcible aborting lock resource, returns execution step 320.
380th, terminate.
Fig. 4 is a kind of main composition schematic diagram of the thread management device based on lock of the present invention.As shown in figure 4, a kind of base In lock thread management device, including:Acquisition module 10, for when acquisition lock resource request is received, acquisition to have distributed lock Resource quantity information;Quantity judge module 20, for distributing lock resource quantity information according to allocated lock money is judged Whether source quantity is more than predetermined threshold value;Distribute module 30, for when allocated lock resource quantity is more than predetermined threshold value, receiving It is described to obtain lock resource request, it is to initiate to obtain the thread distribution lock resource of lock resource request.
All of thread lock is obtained using factory mode in the present invention, so public by an object unified distribution lock resource How many locks are assigned with altogether, and each lock is consumed and how long can be monitored.The present invention arranges pre- to allocated lock quantity If threshold value, if the quantity for monitoring currently allocated lock has reached predetermined threshold value, no longer receive new request, can keep away The problem for exempting to occur excessively taking system processing resources caused by because continuously carrying out lock behavior monitoring.
Preferably, also include:Setup module 40, for arranging the predetermined threshold value;And setting preset duration;It is described pre- If threshold value is the maximum lock resource quantity that user is arranged;The preset duration is that the most long lock resource that user is arranged is occupied Time.
Fig. 5 is that the present invention is a kind of is fully composed schematic diagram based on the thread management device locked.As shown in figure 5, a kind of base In lock thread management device, including:Acquisition module 10, for when acquisition lock resource request is received, acquisition to have distributed lock Resource quantity information;Quantity judge module 20, for distributing lock resource quantity information according to allocated lock money is judged Whether source quantity is more than predetermined threshold value;Distribute module 30, for when allocated lock resource quantity is more than predetermined threshold value, receiving It is described to obtain lock resource request, it is to initiate to obtain the thread distribution lock resource of lock resource request;Monitoring module 50, for monitoring The state of the lock resource of distribution;Duration judge module 60, for judging whether the allocated lock resource occupied time exceedes The preset duration;Release module 70, judges that the allocated lock resource occupied time exceedes the preset duration for working as When, forcible aborting lock resource.
Specifically, if monitor currently allocated lock child resource reaches preset duration by the time that thread takes, Force the thread to discharge the lock resource, reduce the waste of lock resource, be system reasonable arrangement resource.
Preferably, also include:Update module 80, for when there is lock resource to discharge, described in renewal lock number of resources having been distributed Amount information.
It should be noted that the content such as information exchange, implementation procedure in this device between each module and said method reality Example is applied based on same design, particular content can be found in the narration in the inventive method embodiment, and here is omitted.
It should be noted that above-described embodiment can independent assortment as needed.The above is only the preferred of the present invention Embodiment, it is noted that for those skilled in the art, in the premise without departing from the principle of the invention Under, some improvements and modifications can also be made, these improvements and modifications also should be regarded as protection scope of the present invention.

Claims (8)

1. it is a kind of based on the thread management method locked, it is characterised in that including step:
S100, when receive obtain lock resource request when, acquisition distribute lock resource quantity information;
Whether distribute lock resource quantity information described in S200, basis judges allocated lock resource quantity more than predetermined threshold value; If so, step S200 is repeated;Otherwise perform next step;
S300, the acceptance lock that obtains are asked, and are that resource is locked in the thread distribution for initiating acquisition lock resource request.
2. it is as claimed in claim 1 based on the thread management method locked, it is characterised in that also to include before step S100 Step:
S010, the setting predetermined threshold value;The predetermined threshold value is the maximum lock resource quantity that user is arranged;
S020, setting preset duration;The preset duration is the most long lock resource occupied time that user is arranged.
3. it is as claimed in claim 2 based on the thread management method locked, it is characterised in that also including step:
S400, the state for monitoring allocated lock resource;
S500, judge whether allocated lock resource occupied time exceedes the preset duration;If so, then forcible aborting is locked Resource.
4. it is as claimed in claim 3 based on the thread management method locked, it is characterised in that also including step:
S600, when there is lock resource to discharge, update it is described distribute lock resource quantity information.
5. it is a kind of based on the thread management device locked, it is characterised in that to include:
Acquisition module, for when acquisition lock resource request is received, acquisition to distribute lock resource quantity information;
Quantity judge module, judges whether allocated lock resource quantity is big for distributing lock resource quantity information according to In predetermined threshold value;
Distribute module, for when allocated lock resource quantity is more than predetermined threshold value, receiving described acquisition and locking resource request, be Initiate the thread distribution lock resource for obtaining lock resource request.
6. it is as claimed in claim 5 based on the thread management device locked, it is characterised in that also to include:
Setup module, for arranging the predetermined threshold value;And setting preset duration;The predetermined threshold value is that user is arranged most Big lock resource quantity;The preset duration is the most long lock resource occupied time that user is arranged.
7. it is as claimed in claim 6 based on the thread management device locked, it is characterised in that also to include:
Monitoring module, for monitoring the state of allocated lock resource;
Duration judge module, for judging whether the allocated lock resource occupied time exceedes the preset duration;
Release module, for when judging that allocated lock resource occupied time exceedes the preset duration, forcible aborting Lock resource.
8. it is as claimed in claim 7 based on the thread management device locked, it is characterised in that also to include:
Update module, for when there is lock resource to discharge, distributing lock resource quantity information described in renewal.
CN201611100549.3A 2016-12-05 2016-12-05 Lock-based thread management method and lock-based thread management device Pending CN106681809A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611100549.3A CN106681809A (en) 2016-12-05 2016-12-05 Lock-based thread management method and lock-based thread management device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611100549.3A CN106681809A (en) 2016-12-05 2016-12-05 Lock-based thread management method and lock-based thread management device

Publications (1)

Publication Number Publication Date
CN106681809A true CN106681809A (en) 2017-05-17

Family

ID=58866229

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611100549.3A Pending CN106681809A (en) 2016-12-05 2016-12-05 Lock-based thread management method and lock-based thread management device

Country Status (1)

Country Link
CN (1) CN106681809A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109040266A (en) * 2018-08-14 2018-12-18 郑州云海信息技术有限公司 The management method and device locked in micro services framework
CN109344136A (en) * 2018-12-13 2019-02-15 浪潮(北京)电子信息产业有限公司 A kind of access method of shared-file system, device and equipment
CN112905322A (en) * 2021-02-09 2021-06-04 掌阅科技股份有限公司 Resource locking method, computing device and computer storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1917504A (en) * 2005-08-20 2007-02-21 中兴通讯股份有限公司 Method for preventing deadlock caused by accessing shared data of resources
CN103473137A (en) * 2013-09-16 2013-12-25 东软集团股份有限公司 Deadly embrace avoidance resource allocating method and system
CN104252386A (en) * 2013-06-26 2014-12-31 阿里巴巴集团控股有限公司 Data update locking method and equipment
CN104391754A (en) * 2014-10-13 2015-03-04 北京星网锐捷网络技术有限公司 Method and device for processing task exception
CN105677481A (en) * 2015-12-31 2016-06-15 联想(北京)有限公司 Method and system for processing data and electronic equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1917504A (en) * 2005-08-20 2007-02-21 中兴通讯股份有限公司 Method for preventing deadlock caused by accessing shared data of resources
CN104252386A (en) * 2013-06-26 2014-12-31 阿里巴巴集团控股有限公司 Data update locking method and equipment
CN103473137A (en) * 2013-09-16 2013-12-25 东软集团股份有限公司 Deadly embrace avoidance resource allocating method and system
CN104391754A (en) * 2014-10-13 2015-03-04 北京星网锐捷网络技术有限公司 Method and device for processing task exception
CN105677481A (en) * 2015-12-31 2016-06-15 联想(北京)有限公司 Method and system for processing data and electronic equipment

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109040266A (en) * 2018-08-14 2018-12-18 郑州云海信息技术有限公司 The management method and device locked in micro services framework
CN109344136A (en) * 2018-12-13 2019-02-15 浪潮(北京)电子信息产业有限公司 A kind of access method of shared-file system, device and equipment
CN112905322A (en) * 2021-02-09 2021-06-04 掌阅科技股份有限公司 Resource locking method, computing device and computer storage medium
CN112905322B (en) * 2021-02-09 2021-11-19 掌阅科技股份有限公司 Resource locking method, computing device and computer storage medium

Similar Documents

Publication Publication Date Title
CN105320561B (en) Task management method and system
CN103297456B (en) Access method and the distributed system of resource is shared under a kind of distributed system
KR100509794B1 (en) Method of scheduling jobs using database management system for real-time processing
CN110515704B (en) Resource scheduling method and device based on Kubernetes system
US6785756B2 (en) Methods and systems for multi-policy resource scheduling
US6438553B1 (en) Distributed job integrated management system and method
CN106681809A (en) Lock-based thread management method and lock-based thread management device
JP2001331333A5 (en)
US20060048161A1 (en) Resource allocation method and system
CN108182108A (en) A kind of timed task cluster and its execution method
CN109858655B (en) Method and system for reserved test
CN111722928A (en) Resource scheduling method and device, electronic equipment and storage medium
CN109800261B (en) Dynamic control method and device for double-database connection pool and related equipment
CN108446171A (en) Electronic device, distributed system execute method for allocating tasks and storage medium
KR20140089749A (en) Apparatus and method for controlling load allocation of cluster
DE60125540T2 (en) METHOD AND DEVICE FOR A DRAIN PLANNER TO IMPLEMENT A LOG AGAINST TIME ESTIMATES FOR APPLICATION TO A DEVICE NOT CREATING ANY INTERRUPTIONS
CN111163140A (en) Method, apparatus and computer readable storage medium for resource acquisition and allocation
CN114461385A (en) Thread pool scheduling method, device and equipment and readable storage medium
CN105141589B (en) A kind of token of more examples shares the method and system with safeguarding
CN104111876A (en) Dynamic resource management device and method based on Oracle resource plan
CN105094945A (en) Method, equipment and system for virtualization platform thread control
CN111143024A (en) Real-time virtual computing-oriented resource management method
CN107239328A (en) Method for allocating tasks and device
JP2008186358A (en) Data base access system and data base access method, and program
CN114706663A (en) Computing resource scheduling method, medium and computing device

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: 20170517