Search code examples
javamultithreadingthreadpoolrunnable

Pause executing Runnable and/or move it to another Thread


I want to write a thread pool that is able to process Runnables. The execution time of those runnables ist not predictable, but the responsitivity should be as high as possible. To achieve this I want to monitor if there are Runnables that need very long to execute. Those Runnables are considered not as important for resposnitivity as other ones, so if there are such, I want to be able to pause them, in order to execute another, shorter Runnable on the Thread where the more advanced Runnable was executed before and after that resume the execution of the longer lasting Runnable. Is it possible to Pause a Runnable, and save its current state in Java, so I can achieve this?


Solution

  • Thanks to your advices I came to an alternative solution. I will write my own Thread-Pool, consisting of an live pool, which has an limited amount of parallel threads that will execute all incoming tasks. This threads will advance to another pool, consisting of all threads that need to execute a longer lasting task, if they start blocking the pool with those tasks. This way all fast actions will remain in the thread pool, while more advanced task will get their own threads.