CN105893120B - A kind of acquisition methods and device of thread synchronization resource - Google Patents

A kind of acquisition methods and device of thread synchronization resource Download PDF

Info

Publication number
CN105893120B
CN105893120B CN201610249861.2A CN201610249861A CN105893120B CN 105893120 B CN105893120 B CN 105893120B CN 201610249861 A CN201610249861 A CN 201610249861A CN 105893120 B CN105893120 B CN 105893120B
Authority
CN
China
Prior art keywords
resource
thread
weighted value
timestamp
duration
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
CN201610249861.2A
Other languages
Chinese (zh)
Other versions
CN105893120A (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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information 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 Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201610249861.2A priority Critical patent/CN105893120B/en
Publication of CN105893120A publication Critical patent/CN105893120A/en
Application granted granted Critical
Publication of CN105893120B publication Critical patent/CN105893120B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/468Specific access rights for resources, e.g. using capability register
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3442Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for planning or managing the needed capacity
    • 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/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • 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
    • 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/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/48Indexing scheme relating to G06F9/48
    • G06F2209/483Multiproc
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/48Indexing scheme relating to G06F9/48
    • G06F2209/484Precedence
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5013Request control
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5021Priority
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/508Monitor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

The present invention provides the acquisition methods and device of a kind of thread synchronization resource, it is able to satisfy the requirement for being similar to the resource transfer of the thread with priority, the problem of causing thread not execute in time because can not resource be got in time is avoided, reduces the operation risk of whole system to a certain extent;Meanwhile the distribution condition of current all resources is recorded and monitored, whether data foundation is rationally provided for later analysis program threads Resource Design.The acquisition methods of thread synchronization resource of the invention include: the parameter for the acquisition resource that receiving thread is sent;The weighted value of the thread is determined according to the weight parameter;Determine whether the resource is lock state according to the resource parameters, under the premise of determining the resource is lock state, it is blocked state by the status modifier of the thread, then the thread is put into the waiting list of the resource, in the case where the resource is unlocked, which is supplied to the maximum thread of weighted value in the waiting list.

Description

A kind of acquisition methods and device of thread synchronization resource
Technical field
The present invention relates to computer and its software technology field, in particular to a kind of acquisition methods of thread synchronization resource and Device.
Background technique
In java program, what it is based on multithreading is concurrently very common.In order to prevent because multithreading is to same resource (data pair As) access and cause data corruption, so having the application of synchronization (lock), to guarantee that each resource can only at some moment By a thread accesses, while other threads can only block;After the completion of waiting other threads, obstruction thread is waken up.
Since the obstruction of thread and wake-up are all random, and for the thread high for priority, if delayed Resource is obtained, will result in thread can not execute in time, or even can generate biggish risk to whole system.Existing jvm is empty In quasi- machine the processing mode of resource same for multiple thread dispatchings waits money based on thread generally by the way of justice lock The length of time in source carrys out wake-up waiting thread;Other processing modes are substantially random wake-up waiting thread.
In conclusion the processing mode of prior art resource same for multiple thread dispatchings use random or based on etc. The thread that obstruction is waken up to the length of time can not expire for being similar to the requirement of resource transfer of the thread with priority Enough, the problem of not only thread being caused not execute in time because of can not resource be got in time in this way, or even also can be to whole A system operation generates biggish risk;Meanwhile the prior art is not recorded and is supervised to the distribution condition of current all resources Control, but also whether later analysis program threads Resource Design has rationally lacked foundation.
Summary of the invention
In view of this, the present invention provides the acquisition methods and device of a kind of thread synchronization resource, it can satisfy and be similar to tool There is the requirement of the resource transfer of the thread of priority, avoids and cause thread not hold in time because can not resource be got in time Capable problem reduces the operation risk of whole system to a certain extent;Meanwhile to the distribution condition of current all resources It is recorded and has been monitored, whether data foundation is rationally provided for later analysis program threads Resource Design.
To achieve the above object, according to an aspect of the invention, there is provided a kind of acquisition methods of thread synchronization resource.
The acquisition methods of thread synchronization resource of the invention, comprising: the parameter for the acquisition resource that receiving thread is sent;It is described The parameter for obtaining resource includes: resource parameters and weight parameter;The weighted value of the thread is determined according to the weight parameter;Root Determine whether the resource is lock state according to the resource parameters, it, will be described under the premise of determining the resource is lock state The status modifier of thread is blocked state, and then the thread is put into the waiting list of the resource, is unlocked in the resource In the case of, which is supplied to the maximum thread of weighted value in the waiting list.
Optionally, after determining the step of whether resource is lock state according to the resource parameters further include: true Under the premise of the fixed resource is unlocked state, which is supplied to the thread.
Optionally, the weight parameter includes weighted value, weighting function or sky;When the weight parameter is weighted value, The step of weighted value that the thread is determined according to the weight parameter includes the weighted value that will receive as the thread Weighted value;When the weight parameter is weighting function, the weighted value that the thread is determined according to the weight parameter The step of include: the weighted value that the thread is calculated according to the weighting function;When the weight parameter is empty, the basis The weight parameter determines that the step of weighted value of the thread includes: the confirmation weight parameter to be empty, then by default Weighted value of the weighted value as the thread.
Optionally, it is described determine the step of whether resource is lock state according to the resource parameters before, further includes: The recalls information of the resource is determined whether there is according to the resource parameters, if it is present by the recalls information of the resource Resource extinction duration revert to initial duration;Otherwise, the recalls information of the resource is established, and the resource that the resource is arranged is withered away Duration.
Optionally, described to determine that the step of whether resource is lock state includes: according to institute according to the resource parameters State the resource information that resource parameters search the resource;Whether the resource is determined according to the resource lock marker in the resource information For lock state.
Optionally, after the step of parameter for the acquisition resource that receiving thread is sent, further includes: recorded in journal file The timestamp of record, is then stored in database profession by the initial time stamp of the thread application resource, further according to remembering in database The average waiting duration of the timestamp statistics thread of record and the average execution duration of thread.
Optionally, described that the thread is put into after the step in the waiting list of the resource, further includes: in journal file The timestamp of record, is then stored in database profession, further according to data by the middle timestamp for recording the thread and entering waiting list The average waiting duration of the timestamp statistics thread recorded in library and the average execution duration of thread.
Optionally, it before the described the step of resource is supplied to the maximum thread of weighted value in the waiting list, also wraps Include: record thread waits for timestamp in journal file, is then stored in database profession the timestamp of record, further according to The average waiting duration of the timestamp statistics thread recorded in database and the average execution duration of thread.
Optionally, it after the described the step of resource is supplied to the maximum thread of weighted value in the waiting list, also wraps Include: then the timestamp of record is stored in database by timestamp of the record thread after getting resource in journal file In, the average execution duration of average waiting duration and thread further according to the timestamp statistics thread recorded in database;It is described Timestamp after getting resource includes: the timestamp that resource is locked timestamp and resource is abandoned locking.
Optionally, the described the step of resource is supplied to the maximum thread of weighted value in the waiting list include: by etc. Descending arrangement is carried out according to weight to the thread in queue;The resource is supplied to come first thread;And it is described to wait After the step of carrying out descending arrangement according to weight to the thread in queue, further includes: it is instructed according to the thread scheduling received, The change of position of the record thread in affiliated waiting list, and the weighted value of the thread after position change is revised as position and is become Weighted value corresponding to the position after change.
According to another aspect of the present invention, a kind of acquisition device of thread synchronization resource is provided.
The acquisition device of thread synchronization resource of the invention includes: receiving module, the acquisition money sent for receiving thread The parameter in source;The parameter for obtaining resource includes: resource parameters and weight parameter;Determining module, for according to the weight Parameter determines the weighted value of the thread;First provides module, for determining whether the resource is lock according to the resource parameters Determine state, under the premise of determining the resource is lock state, is blocked state by the status modifier of the thread, then should Thread is put into the waiting list of the resource, and in the case where the resource is unlocked, which is supplied in the waiting list The maximum thread of weighted value.
Optionally, further include the second offer module, for determine the resource be unlocked state under the premise of, by the money Source is supplied to the thread.
Optionally, the weight parameter includes weighted value, weighting function or sky;When the weight parameter is weighted value, The determining module is used for using the weighted value received as the weighted value of the thread;When the weight parameter is weighting function When, the determining module is used to be calculated the weighted value of the thread according to the weighting function;When the weight parameter is empty, The determining module is for confirming the weight parameter for sky, then using the weighted value of default as the weighted value of the thread.
It optionally, further include that information checks module, for determining whether there is the tune of the resource according to the resource parameters With information, if it is present the resource extinction duration in the recalls information of the resource is reverted to initial duration;Otherwise, it establishes The recalls information of the resource, and the resource extinction duration of the resource is set.
Optionally, the first offer module is also used to search the resource information of the resource according to the resource parameters, then Determine whether the resource is lock state according to the resource lock marker in the resource information.
It optionally, further include the first logging modle, when for recording the starting of the thread application resource in journal file Between stab, then the timestamp of record is stored in database profession, further according to the flat of the timestamp statistics thread recorded in database The average execution duration of equal waiting time and thread.
Optionally, further include the second logging modle, for recorded in journal file the thread enter waiting list when Between stab, then the timestamp of record is stored in database profession, further according to the flat of the timestamp statistics thread recorded in database The average execution duration of equal waiting time and thread.
Optionally, further include third logging modle, in journal file record thread wait for timestamp, then The timestamp of record is stored in database profession, further according to the average waiting duration of the timestamp statistics thread recorded in database With the average execution duration of thread.
Optionally, further include the 4th logging modle, in journal file record thread get after resource when Between stab, then the timestamp of record is stored in database profession, further according to the flat of the timestamp statistics thread recorded in database The average execution duration of equal waiting time and thread;The timestamp got after resource includes: that resource is locked timestamp The timestamp of locking is abandoned with resource.
Optionally, the first offer module is also used to the thread in waiting list carrying out descending arrangement according to weight, The resource is supplied to again come first thread;And described device further includes thread scheduling module, is received for basis Thread scheduling instruction, the change of position of the record thread in affiliated waiting list, and by the power of the thread after position change Weight values are revised as weighted value corresponding to the position after change in location.
According to a further aspect of the invention, a kind of acquisition device of thread synchronization resource is provided.
The acquisition device of thread synchronization resource of the invention, comprising: memory and processor;Wherein, the memory is deposited Storage instruction;The processor executes described instruction, is used for: the parameter for the acquisition resource that receiving thread is sent;The acquisition resource Parameter include: resource parameters and weight parameter;The weighted value of the thread is determined according to the weight parameter;According to the money Source parameter determines whether the resource is lock state, under the premise of determining the resource is lock state, by the shape of the thread State is revised as blocked state, and then the thread is put into the waiting list of the resource, will in the case where the resource is unlocked The resource is supplied to the maximum thread of weighted value in the waiting list.
According to the technique and scheme of the present invention, the thread of waiting is waken up by being then based on the weighted value of thread, because This can satisfy the requirement for being similar to the resource transfer of the thread with priority, avoid due to can not get resource in time The problem of causing thread not execute in time reduces the operation risk of whole system to a certain extent;Meanwhile in thread etc. To in calling process, the distribution condition of current all resources be recorded and monitored, thus for later analysis journey Whether the design of sequence thread resources rationally provides data foundation;And the technical solution can also be to the thread etc. in waiting list To sequentially be changed, thus, the flexibility of scheduling of resource is also improved to a certain extent.
Detailed description of the invention
Attached drawing for a better understanding of the present invention, does not constitute an undue limitation on the present invention.Wherein:
Fig. 1 is a kind of schematic diagram of the acquisition device of thread synchronization resource according to an embodiment of the present invention;
Fig. 2 is a kind of schematic diagram of the acquisition methods of thread synchronization resource according to an embodiment of the present invention;
Fig. 3 is the schematic diagram of the acquisition methods of another thread synchronization resource according to an embodiment of the present invention.
Specific embodiment
Below in conjunction with attached drawing, an exemplary embodiment of the present invention will be described, including the various of the embodiment of the present invention Details should think them only exemplary to help understanding.Therefore, those of ordinary skill in the art should recognize It arrives, it can be with various changes and modifications are made to the embodiments described herein, without departing from scope and spirit of the present invention.Together Sample, for clarity and conciseness, descriptions of well-known functions and structures are omitted from the following description.
Fig. 1 is a kind of schematic diagram of the acquisition device of thread synchronization resource according to an embodiment of the present invention.The present invention is implemented The acquisition device 10 of the thread synchronization resource of example specifically includes that receiving module 11, determining module 12 and the first offer module 13;The parameter for the acquisition resource that receiving module 11 is sent for receiving thread;The parameter for obtaining resource includes: resource parameters And weight parameter;Determining module 12 is used to determine the weighted value of the thread according to the weight parameter;First provides module 13 For determining whether the resource is lock state according to the resource parameters, under the premise of determining the resource is lock state, It is blocked state by the status modifier of the thread, then the thread is put into the waiting list of the resource, in the resource quilt In the case where unlock, which is supplied to the maximum thread of weighted value in the waiting list.
The acquisition device 10 of the thread synchronization resource of the embodiment of the present invention may also include the second offer module, in determination Under the premise of the resource is unlocked state, which is supplied to the thread.
The weight parameter being previously mentioned in the embodiment of the present invention can be weighted value, weighting function or sky;
When the weight parameter is weighted value, determining module 12 is used for using the weighted value received as the power of the thread Weight values;
When the weight parameter is weighting function, determining module 12 is used to that the thread to be calculated according to the weighting function Weighted value;
When the weight parameter is empty, determining module 12 is for confirming the weight parameter for sky, then by default Weighted value of the weighted value as the thread.
The acquisition device 10 of the thread synchronization resource of the embodiment of the present invention may also include information and check that module (is not shown in figure Out), for determining whether there is the recalls information of the resource according to the resource parameters, if it is present by the tune of the resource Initial duration is reverted to the resource extinction duration in information;Otherwise, the recalls information of the resource is established, and the resource is set Resource extinction duration.
First offer module 13 of the acquisition device 10 of the thread synchronization resource of the embodiment of the present invention can also be used according to institute The resource information that resource parameters search the resource is stated, determines that the resource is further according to the resource lock marker in the resource information No is lock state.
The acquisition device 10 of the thread synchronization resource of the embodiment of the present invention may also include the first logging modle and (not show in figure Out), for recording the initial time stamp of the thread application resource in journal file, the timestamp of record is then stored in number According to the average execution duration for the average waiting duration and thread in library, counting thread further according to the timestamp recorded in database.
The acquisition device 10 of the thread synchronization resource of the embodiment of the present invention may also include the second logging modle and (not show in figure Out), the timestamp of waiting list is entered for recording the thread in journal file, the timestamp of record is then stored in number According to the average execution duration for the average waiting duration and thread in library, counting thread further according to the timestamp recorded in database.
The acquisition device 10 of the thread synchronization resource of the embodiment of the present invention may also include third logging modle and (not show in figure Out), in journal file record thread wait for timestamp, then the timestamp of record is stored in database profession, The average execution duration of average waiting duration and thread further according to the timestamp statistics thread recorded in database.
The acquisition device 10 of the thread synchronization resource of the embodiment of the present invention may also include the 4th logging modle and (not show in figure Out), for timestamp of the record thread after getting resource in journal file, the timestamp of record is then stored in number According to the average execution duration for the average waiting duration and thread in library, counting thread further according to the timestamp recorded in database; The timestamp got after resource includes: the timestamp that resource is locked timestamp and resource is abandoned locking.
First offer module 13 of the acquisition device 10 of the thread synchronization resource of the embodiment of the present invention can also be used to wait Thread in queue carries out descending arrangement according to weight, then the resource is supplied to come first thread;
And described device may also include thread scheduling module (not shown), for according to the thread scheduling received Instruction, the change of position of the record thread in affiliated waiting list, and the weighted value of the thread after position change is revised as Weighted value corresponding to the position after change in location.
Fig. 2 is a kind of schematic diagram of the acquisition methods of thread synchronization resource according to an embodiment of the present invention.As shown in Fig. 2, The executing subject of the acquisition methods of the thread synchronization resource of the embodiment of the present invention is obtaining for the thread synchronization resource being previously mentioned in Fig. 1 Device 10 is taken, this method mainly includes the following steps S20 to S24.
Step S20: the parameter for the acquisition resource that receiving thread is sent.The parameter packet for the acquisition resource being previously mentioned in the step It includes: resource parameters and weight parameter;When thread needs to call resource, need the resource parameters for the resource called and the line The weight parameter of journey is sent to the acquisition device 10 of thread synchronization resource;Meanwhile the acquisition device 10 of thread synchronization resource is in day The initial time stamp of the thread application resource is recorded in will file.
Step S21: the weighted value of the thread is determined according to the weight parameter.In this step, thread synchronization resource Acquisition device 10 receive thread transmission resource parameters and weight parameter after, which is determined according to weight parameter therein The weighted value of journey;Weight parameter can be weighted value, weighting function or sky;When weight parameter is weighted value (for example, receiving Weighted value be 8, it is assumed that the value range of weighted value is [1,10]), then, the acquisition device 10 of thread synchronization resource will receive Weighted value of the weighted value 8 arrived as the thread;When weight parameter is weighting function, the acquisition device 10 of thread synchronization resource Corresponding weighted value is calculated according to the weighting function received, and using the weighted value being calculated as the weight of the thread Value;When weight parameter is empty, the acquisition device 10 of thread synchronization resource first confirms that received weight parameter is sky, so Afterwards using the weighted value of default as the weighted value of the thread.
Step S22: determining whether the resource is lock state according to the resource parameters, if the resource is locking shape State thens follow the steps S23;Otherwise, step S24 is executed.It is same due to often will appear in the process of thread dispatching resource A resource is needed by the situation of multiple thread dispatchings, therefore in order to guarantee that each resource can only be by a thread at some moment Access, needs to lock resource when resource is by thread dispatching;In step S22, the acquisition device of thread synchronization resource 10 based on the received resource parameters search the resource information of the resource, and identified according to the resource lock in the resource information Position determines whether the resource is lock state.
Step S23: it is blocked state by the status modifier of the thread, then which is put into the waiting team of the resource In column, in the case where the resource is unlocked, which is supplied to the maximum thread of weighted value in the waiting list.In the step In rapid, the thread in the resource waiting list is carried out descending according to the size of weighted value by the acquisition device 10 of thread synchronization resource Arrangement, and record in journal file the timestamp that the thread enters waiting list;In the case where the resource is unlocked, Weighted value is recorded in journal file come first thread wait for timestamp;The resource is finally supplied to the waiting team Weighted value comes first thread in column, and timestamp of the record thread after getting resource in journal file, wherein line Timestamp of the journey after getting resource includes: the timestamp that resource is locked timestamp and resource is abandoned locking;Thread is same Timestamp recorded in journal file can be periodically stored in database profession by the acquisition device 10 for walking resource, further according to database The average waiting duration of the timestamp statistics thread of middle record and the average execution duration of thread, for monitoring and recording resource Distribution and calling situation, and data foundation is provided when whether later analysis program threads Resource Design is reasonable.
Step S24: the resource is supplied directly to the thread.
It is therefore, right in order to clear up the resource data in memory in the technical solution of the embodiment of the present invention The corresponding resource extinction duration of resource settings in memory, can be under the premise of resource be called for a long time, timing Memory is cleared up, memory headroom is saved;Resource parameters determine whether the acquisition device 10 of thread synchronization resource based on the received There are the recalls informations of the resource, if it is present the resource extinction duration in the recalls information of the resource is reverted to initially Duration;Otherwise, the recalls information of the resource is established, and the resource extinction duration of the resource is set.The acquisition of thread synchronization resource Device 10 is not called in resource and resource extinction time it is a length of 0 when, which is purged.
In the technical solution of the embodiment of the present invention, the acquisition device 10 of thread synchronization resource can be according to the thread tune received Degree instruction, the change of position of the record thread in affiliated waiting list, and the weighted value of the thread after position change is modified For weighted value corresponding to the position after change in location.The acquisition device 10 of thread synchronization resource can carry a terminal interface, For showing currently called resource, the waiting thread in the corresponding waiting list of resource and remembered according in database The average waiting duration for the thread that the timestamp of record counts is peaceful to be performed both by the information such as duration, and user can pass through operation The waiting sequence of thread in resource waiting list is changed by terminal interface by way of dragging, to generate corresponding Thread scheduling instruction, and instruct according to the thread scheduling change of position of the record thread in affiliated waiting list, and by position The weighted value for setting the thread after changing is revised as weighted value corresponding to the position after change in location.Such as: resource etc. To which there are three the threads waited, i.e. 3 (weighted value of thread 1 (weighted value 9), thread 2 (weighted value 8) and thread in queue For 7);If the needs of thread 2 first carry out at this time, it is possible to which thread 2 is placed into the position of thread 1, thread by the mode pulled The change of 10 record thread of acquisition device, 2 position of isochronous resources, and should be for originally in the position by the weighted value of thread 2 Thread 1 weighted value, and by the weighted value of thread 1 should for it is original in second thread 2 weighted value.
Fig. 3 is the schematic diagram of the acquisition methods of another thread synchronization resource according to an embodiment of the present invention.Such as Fig. 3 institute Show, the acquisition device 30 of thread synchronization resource of the invention mainly includes memory 31 and processor 32;Wherein, the memory 31 store instructions;The processor 32 executes described instruction, the parameter for the acquisition resource that receiving thread is sent;The acquisition The parameter of resource includes: resource parameters and weight parameter;The weighted value of the thread is determined according to the weight parameter;According to institute It states resource parameters and determines whether the resource is lock state, under the premise of determining the resource is lock state, by the thread Status modifier be blocked state, then the thread is put into the waiting list of the resource, the case where the resource is unlocked Under, which is supplied to the maximum thread of weighted value in the waiting list.
Technical solution according to an embodiment of the present invention calls out the thread of waiting by being then based on the weighted value of thread It wakes up, therefore can satisfy the requirement for being similar to the resource transfer of the thread with priority, avoid because that can not get in time Resource and the problem of cause thread not execute in time, reduce the operation risk of whole system to a certain extent;Meanwhile Thread is waited in calling process, and the distribution condition of current all resources is recorded and monitored, thus in the future Whether analysis program threads Resource Design rationally provides data foundation;And the technical solution can also be in waiting list Thread waiting sequence is changed, thus, the flexibility of scheduling of resource is also improved to a certain extent.
Above-mentioned specific embodiment, does not constitute a limitation on the scope of protection of the present invention.Those skilled in the art should be bright It is white, design requirement and other factors are depended on, various modifications, combination, sub-portfolio and substitution can occur.It is any Made modifications, equivalent substitutions and improvements etc. within the spirit and principles in the present invention, should be included in the scope of the present invention Within.

Claims (20)

1. a kind of acquisition methods of thread synchronization resource characterized by comprising
The parameter for the acquisition resource that receiving thread is sent;The parameter for obtaining resource includes: resource parameters and weight parameter;
The weighted value of the thread is determined according to the weight parameter;
Determine whether the resource is lock state according to the resource parameters, under the premise of determining the resource is lock state, It is blocked state by the status modifier of the thread, then the thread is put into the waiting list of the resource, in the resource quilt In the case where unlock, which is supplied to the maximum thread of weighted value in the waiting list;
The described the step of resource is supplied to the maximum thread of weighted value in the waiting list includes:
Thread in waiting list is subjected to descending arrangement according to weight;
The resource is supplied to come first thread;
And after the step of thread by waiting list carries out descending arrangement according to weight, further includes: according to reception The thread scheduling instruction arrived, the change of position of the record thread in affiliated waiting list, and by the thread after position change Weighted value is revised as weighted value corresponding to the position after change in location.
2. the method according to claim 1, wherein determining whether the resource is locking according to the resource parameters After the step of state further include: under the premise of determining the resource is unlocked state, which is supplied to the thread.
3. the method according to claim 1, wherein the weight parameter includes weighted value, weighting function or sky;
When the weight parameter is weighted value, the packet the step of weighted value that the thread is determined according to the weight parameter The weighted value that will be received is included as the weighted value of the thread;
When the weight parameter is weighting function, the step of the weighted value that the thread is determined according to the weight parameter It include: the weighted value that the thread is calculated according to the weighting function;
When the weight parameter is empty, the step of weighted value that the thread is determined according to the weight parameter, includes: The weight parameter is confirmed for sky, then using the weighted value of default as the weighted value of the thread.
4. the method according to claim 1, wherein it is described according to the resource parameters determine the resource whether be Before the step of lock state, further includes: the recalls information of the resource is determined whether there is according to the resource parameters, if deposited The resource extinction duration in the recalls information of the resource is then being reverted into initial duration;Otherwise, the calling letter of the resource is established Breath, and the resource extinction duration of the resource is set.
5. the method according to claim 1, wherein it is described according to the resource parameters determine the resource whether be The step of lock state includes:
The resource information of the resource is searched according to the resource parameters;
Determine whether the resource is lock state according to the resource lock marker in the resource information.
6. the method according to claim 1, wherein receiving thread send acquisition resource parameter the step of it Afterwards, further includes: then the timestamp of record is stored in by the initial time stamp that the thread application resource is recorded in journal file In database, further according to recorded in database timestamp statistics thread average waiting duration and thread average execution when It is long.
7. the method according to claim 1, wherein described be put into the thread in the waiting list of the resource After step, further includes: the timestamp that the thread enters waiting list is recorded in journal file, then by the timestamp of record It is stored in database profession, is held further according to the average waiting duration and being averaged for thread of the timestamp statistics thread recorded in database Row duration.
8. the method according to claim 1, wherein described be supplied to weighted value in the waiting list for the resource Before the step of maximum thread, further includes: record thread waits for timestamp in journal file, then by record when Between stab and be stored in database profession, the average waiting duration and thread further according to the timestamp statistics thread recorded in database it is flat It is performed both by duration.
9. the method according to claim 1, wherein described be supplied to weighted value in the waiting list for the resource After the step of maximum thread, further includes: then timestamp of the record thread after getting resource in journal file will The timestamp of record is stored in database profession, further according to recorded in database timestamp statistics thread average waiting duration and The average execution duration of thread;The timestamp got after resource includes: that resource is locked timestamp and resource is abandoned The timestamp of locking.
10. a kind of acquisition device of thread synchronization resource characterized by comprising
Receiving module, the parameter for the acquisition resource that receiving thread is sent;The parameter for obtaining resource includes: resource parameters And weight parameter;
Determining module, for determining the weighted value of the thread according to the weight parameter;
First provides module, for determining whether the resource is lock state according to the resource parameters, is determining that the resource is Under the premise of lock state, it is blocked state by the status modifier of the thread, then which is put into the waiting of the resource In queue, in the case where the resource is unlocked, which is supplied to the maximum thread of weighted value in the waiting list;
The first offer module is also used to the thread in waiting list carrying out descending arrangement according to weight, then the resource is mentioned Supply comes first thread;
And described device further includes thread scheduling module, for according to the thread scheduling instruction received, record thread to be in institute Belong to the change of the position in waiting list, and the weighted value of the thread after position change is revised as the position institute after change in location Corresponding weighted value.
11. device according to claim 10, which is characterized in that further include the second offer module, for determining the money Under the premise of source is unlocked state, which is supplied to the thread.
12. device according to claim 10, which is characterized in that the weight parameter include weighted value, weighting function or It is empty;
When the weight parameter is weighted value, the determining module is used for using the weighted value received as the weight of the thread Value;
When the weight parameter is weighting function, the determining module is used to that the thread to be calculated according to the weighting function Weighted value;
When the weight parameter is empty, the determining module is for confirming the weight parameter for sky, then by the power of default Weighted value of the weight values as the thread.
13. device according to claim 10, which is characterized in that further include that information checks module, for according to the money Source parameter determines whether there is the recalls information of the resource, if it is present the resource in the recalls information of the resource is withered away Duration reverts to initial duration;Otherwise, the recalls information of the resource is established, and the resource extinction duration of the resource is set.
14. device according to claim 10, which is characterized in that the first offer module is also used to according to the resource Parameter searches the resource information of the resource, determines whether the resource is lock further according to the resource lock marker in the resource information Determine state.
15. device according to claim 10, which is characterized in that further include the first logging modle, in journal file The timestamp of record, is then stored in database profession, further according to data by the middle initial time stamp for recording the thread application resource The average waiting duration of the timestamp statistics thread recorded in library and the average execution duration of thread.
16. device according to claim 10, which is characterized in that further include the second logging modle, in journal file The timestamp of record, is then stored in database profession, further according to data by the middle timestamp for recording the thread and entering waiting list The average waiting duration of the timestamp statistics thread recorded in library and the average execution duration of thread.
17. device according to claim 10, which is characterized in that further include third logging modle, in journal file Middle record thread waits for timestamp, is then stored in database profession the timestamp of record, further according to recording in database Timestamp statistics thread average waiting duration and thread average execution duration.
18. device according to claim 10, which is characterized in that further include the 4th logging modle, in journal file The timestamp of record, is then stored in database profession, further according to data by timestamp of the middle record thread after getting resource The average waiting duration of the timestamp statistics thread recorded in library and the average execution duration of thread;It is described get resource after Timestamp includes: the timestamp that resource is locked timestamp and resource is abandoned locking.
19. a kind of acquisition device of thread synchronization resource characterized by comprising memory and processor;Wherein, described to deposit Reservoir store instruction;
The processor executes described instruction, for realizing the method as described in any in claim 1-9.
20. a kind of computer-readable medium, is stored thereon with computer program, which is characterized in that described program is held by processor The method as described in any in claim 1-9 is realized when row.
CN201610249861.2A 2016-04-21 2016-04-21 A kind of acquisition methods and device of thread synchronization resource Active CN105893120B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610249861.2A CN105893120B (en) 2016-04-21 2016-04-21 A kind of acquisition methods and device of thread synchronization resource

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610249861.2A CN105893120B (en) 2016-04-21 2016-04-21 A kind of acquisition methods and device of thread synchronization resource

Publications (2)

Publication Number Publication Date
CN105893120A CN105893120A (en) 2016-08-24
CN105893120B true CN105893120B (en) 2019-07-30

Family

ID=56704183

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610249861.2A Active CN105893120B (en) 2016-04-21 2016-04-21 A kind of acquisition methods and device of thread synchronization resource

Country Status (1)

Country Link
CN (1) CN105893120B (en)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106372179B (en) * 2016-08-31 2020-04-03 上海爱数信息技术股份有限公司 Method and system for detecting document change and synchronization
CN106775974B (en) * 2016-12-07 2019-12-10 国云科技股份有限公司 Method for realizing distributed priority queuing lock
CN107133092A (en) * 2017-05-24 2017-09-05 努比亚技术有限公司 Multi-thread synchronization processing method, terminal and computer-readable recording medium
CN107147922B (en) * 2017-06-20 2019-06-18 深圳市茁壮网络股份有限公司 Frequency point resource allocation methods and frequency point resource management server
CN109308220B (en) * 2017-07-26 2021-12-14 华为技术有限公司 Shared resource allocation method and device
CN107967150B (en) * 2017-12-19 2021-10-15 郑州云海信息技术有限公司 Method, device, equipment and storage medium for determining thread execution sequence
CN110381124B (en) * 2019-06-28 2022-03-25 苏州浪潮智能科技有限公司 Lock resource application method and device
CN110611746B (en) * 2019-09-03 2021-06-29 深圳市云网万店电子商务有限公司 Multi-camera synchronization method and distributed system
CN110688102B (en) * 2019-09-29 2022-03-22 北京浪潮数据技术有限公司 Method, system, device and storage medium for capturing execution result of asynchronous interface
CN110865977A (en) * 2019-11-05 2020-03-06 中盈优创资讯科技有限公司 Method and device for operating HDFS directory by multiple programs

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2005096149A1 (en) * 2004-04-02 2005-10-13 Symbian Software Limited Improvements in or relating to an operating system for a computing device
CN1983193A (en) * 2005-12-12 2007-06-20 国际商业机器公司 System and method for processing information
CN105408873A (en) * 2013-05-02 2016-03-16 微软技术许可有限责任公司 Activity based sampling of diagnostics data
EP3005110A1 (en) * 2013-05-31 2016-04-13 Microsoft Technology Licensing, LLC Efficient priority-aware thread scheduling

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7886300B1 (en) * 2006-09-26 2011-02-08 Oracle America, Inc. Formerly Known As Sun Microsystems, Inc. Mechanism for implementing thread synchronization in a priority-correct, low-memory safe manner
US9003413B1 (en) * 2009-09-28 2015-04-07 Xilinx, Inc. Thread synchronization by transitioning threads to spin lock and sleep state
US8793697B2 (en) * 2012-02-23 2014-07-29 Qualcomm Incorporated Method and system for scheduling requests in a portable computing device
US9274832B2 (en) * 2013-02-07 2016-03-01 Htc Corporation Method and electronic device for thread scheduling
CN103902732A (en) * 2014-04-18 2014-07-02 北京大学 Construction and network resource collection method of self-adaption network resource collection system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2005096149A1 (en) * 2004-04-02 2005-10-13 Symbian Software Limited Improvements in or relating to an operating system for a computing device
CN1973266A (en) * 2004-04-02 2007-05-30 西姆毕恩软件有限公司 Improvements in or relating to an operating system for a computing device
CN1983193A (en) * 2005-12-12 2007-06-20 国际商业机器公司 System and method for processing information
CN105408873A (en) * 2013-05-02 2016-03-16 微软技术许可有限责任公司 Activity based sampling of diagnostics data
EP3005110A1 (en) * 2013-05-31 2016-04-13 Microsoft Technology Licensing, LLC Efficient priority-aware thread scheduling

Also Published As

Publication number Publication date
CN105893120A (en) 2016-08-24

Similar Documents

Publication Publication Date Title
CN105893120B (en) A kind of acquisition methods and device of thread synchronization resource
CN109828833B (en) Queuing system and method for neural network training task
CN109831500B (en) Synchronization method for configuration file and Pod in Kubernetes cluster
CN109918141B (en) Thread execution method, thread execution device, terminal and storage medium
CN105247529B (en) The synchronous voucher hash between directory service
US8261266B2 (en) Deploying a virtual machine having a virtual hardware configuration matching an improved hardware profile with respect to execution of an application
US6553369B1 (en) Approach for performing administrative functions in information systems
CN102096603B (en) Task decomposition control method in MapReduce system and scheduling node equipment
US8930584B2 (en) System and method for providing a linearizable request manager
US20180052711A1 (en) Method and system for scheduling video analysis tasks
US9292344B2 (en) Reservation scheduler for real-time operating systems in wireless sensor networks
CN103019805A (en) Timer setting method under multithreading environment
US20080086733A1 (en) Computer micro-jobs
CN103092682A (en) Asynchronous network application program processing method
CN101566977A (en) Method, device and system of processor accessing shared data
CN111416825A (en) Inter-thread lock-free log management method and system, terminal and storage medium
CN104252386B (en) The locking method and equipment of data renewal
CN112241400A (en) Method for realizing distributed lock based on database
CN104376096B (en) The method of asynchronous refresh based on buffering area
US11036542B2 (en) Automatically limiting repeated checking on completion of a command without relinquishing a processor
CN107368498A (en) The lock for optimizing MySQL Pessimistic Lockings waits the method and device of time-out time
WO2016078388A1 (en) Data aging method and apparatus
CN101470627B (en) Method for implementing parallel multi-core configuration lock on MIPS platform
CN106603215A (en) Unfair network channel resource sharing method based on ZigBee
EP2413240A1 (en) Computer micro-jobs

Legal Events

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