Is there a way to prioritize tasks for execution in a Java ThreadPoolExecutor? The problem that I am facing is that there are threads that need to be executed in order when based on an identical specified execution identifier.
They are all submitted to the same ThreadPoolExecutor but due to processing delays it is possible that task A2 completes before task A1 (which has the same execution identifier). They should follow the same ordering as when they enter while not blocking other tasks (with different execution identifiers) from executing (e.g. B1, B2, C1, etc.).
Is there a common pattern for handling a problem like that? For example, tasks A1, B1, B2, A2, C1 enter the pool for processing. They should be processed in the following manner:
A1
B1
B2 (if B1 has completed, otherwise wait until B1 completes while A2 or C1 take turn)
A2 (if A1 has completed, otherwise wait until A1 completes while B2, if not started already, or C1 take turn)
C1