Class MultiThreadedActionGraphBuilder

  • All Implemented Interfaces:
    ActionGraphBuilder, BuildRuleResolver, SourcePathRuleFinder

    public class MultiThreadedActionGraphBuilder
    extends AbstractActionGraphBuilder
    Implementation of BuildRuleResolver that supports build rules being created in parallel.

    In order to prevent race-conditions and duplicate work, this implementation imposes additional semantics for concurrent access:

    • Rules are stored in futures.
    • Accessing incomplete rules from the current thread behaves as if the rule does not exist. Accessing incomplete rules from other threads waits for the rule future to complete.
    The implementation parallelizes work via the parallelizer and when it receives a call for multiple things at the same time via requireAllRules or computeAllIfAbsent. For all of these cases, it basically creates a list of Tasks, schedules them, tries to finish them on the current thread and then waiting for them. When a Task is scheduled, we submit a job to the executor service to complete that task.

    This means that a task that is doing work will only recursively process tasks that it has directly asked for (i.e. stack traces will look nice). In the case where work is done by another thread, stack traces will be captured on that thread and then re-thrown from the thread that requested the work.