0
votes

Suppose I have a thread pool with 10 threads. Let's say that one of the threads in the pool executes some task. I want that in certain cases, the task will stop its execution, the thread will take another task and only later it will return to the previous task and continue it from where it stopped.

Is this possible? How can I do it?

It sounds like you're not using threads as threads, but making them act like thread schedulers as well. It might be far easier to map tasks to threads, and keep your thread scheduling at the process level. Or find a well tested, long established java thread/task scheduling library and start using that. - Mike 'Pomax' Kamermans
This requires a lot of coordination. The task implementation needs to have some kind of checkpoint that is resumable. This is not built in to Java. - Sotirios Delimanolis