A common problem in concurrent programming arises when you have various concurrent tasks available to solve a problem, but you are only interested in the first result. For example, you want to sort an array. You have various sort algorithms. You can launch all of them and get the result of the first one that sorts the array, that is, the fastest sorting algorithm for a given array.
In this recipe, you will learn how to implement this scenario using the ThreadPoolExecutor class. You are going to use two mechanisms to try and validate a user. The user will be validated if one of these mechanisms is able to validate it.