2012年3月21日星期三

Beats HeadphonesThe CometPipe data sent a change Author: Fangweng (Wen Chu) scene: premise: the long

The CometPipe data sent a change Author: Fangweng (Wen Chu) scene: premise: the long connecting push (each request to maintain a long session time).In the event driven mode, multiple threads may be at the same time to complete the task and sends data through the Http long connection, the need for Response have concurrent protection.
The first edition adds an lock, obtained after the use of Response.Each thread's process: get lock à use response à release lock.In the same channel events generated when the number of concurrent, because use response “ ”,Vibram Five Fingers Shoes, make a large number of life cycle increase (sequence to obtain a lock), context switching frequency, system high load.
Second Edition (now version) to remove lock,Discount Coach, one for each request session adding a queue and a background thread.Each thread's process: add message to queue.Block to wait message and background thread deliver.
The first edition of the problem does not exist, but in the absence of message downlink time, a background thread block wait,Nike Air Max Women, the memory is still some waste.Complex but may not have good effect in the version from above, need to do is to prevent the transmission data into competition Affairs (that is, a period of only one thread is responsible for the queue data acquisition and issued), need to reuse thread for multiple requests processed downlink assignment.
Generally explain process: 1 each thread in the queue when the need to obtain read-write lock read lock, then the data will be put in the queue.Specific acquired read lock to finally talk.2 thread to determine whether have background support thread to handle the message issued,Beats Headphones, if not try to operate needworkerflag atomic Boolean object.
3 thread if the success of the needworkerflag atomic Boolean object from the true into a false state, then said he had been made the incident thread token, to the thread pool initiate execution of sending message task.
4 pool of threads receive task, assigning a thread loop to obtain data and sends the instantaneous, until the queue is empty.5 acquisition of the write lock, to check if the queue has a data, if there is a downward, and then modify the needworkerflag true,UGG Boots UK, the final release of the write lock.
(read and write lock is to ensure in a background thread exit queue has been added data fully executed, without concurrent lead to legacy data in the queue but no thread to handle the situation, the disadvantage is in the write lock critical zone which will write action can block the external at that time put data process) design is complicated, can bring more than second good design is possible in the news with lower when making full use of resources, but the disadvantages are still many, including a thread switch, a thread exited short-time occlusion, the thread pool size considerations.
Related articles:

没有评论:

发表评论