public static ConcurrentMap<String, Long> getResourceUsage(boolean globalConcurrencyEnabled, List<InstanceState> activeStates, Set<WorkflowInstance> timedOutInstances, WorkflowResourceDecorator resourceDecorator, Map<WorkflowId, Workflow> workflows) { return activeStates.parallelStream() .filter(entry -> !timedOutInstances.contains(entry.workflowInstance())) .filter(entry -> isConsumingResources(entry.runState().state())) .flatMap(instanceState -> pairWithResources(globalConcurrencyEnabled, instanceState, workflows, resourceDecorator)) .collect(groupingByConcurrent( ResourceWithInstance::resource, ConcurrentHashMap::new, counting())); }