Just be aware, each of these queries ultimately results in a SQL call to the database so it could be potentially costly in high volume. There may be a better way of getting the same data if the instances share a common business key or process variables that you can do a direct Task query on and group by process Instance.
Re: Get active process Instances with associated tasks
Thanks Greg. I see that there is method processInstanceIdIn(List<String> processInstanceIds) which takes in list of processInstance ids. Is it possible to use the mentioned method to get the list of tasks across many instances and group them by processInstance?