@ GuardedBy ( "evictionLock" ) void drainBuffers ( int maxToDrain ) { // A mostly strict ordering is achieved by observing that each buffer // contains tasks in a weakly sorted order starting from the last drain. // The buffers can be merged into a sorted list in O(n) time by using // counting sort and chaining on a collision. // The output is capped to the expected number of tasks plus additional // slack to optimistically handle the concurrent additions to the buffers. Task [ ] tasks = new Task [ maxToDrain ] ; // Moves the tasks into the output array, applies them, and updates the // marker for the starting order of the next drain. int maxTaskIndex = moveTasksFromBuffers ( tasks ) ; runTasks ( tasks , maxTaskIndex ) ; updateDrainedOrder ( tasks , maxTaskIndex ) ; }
Drains the buffers and applies the pending operations .