How to indefinitely pause a thread in Java and later resume it?

Posted by Carlos Torres on Stack Overflow See other posts from Stack Overflow or by Carlos Torres
Published on 2010-04-12T14:29:52Z Indexed on 2010/04/12 14:33 UTC
Read the original article Hit count: 332

Filed under:
|
|
|

Maybe this question has been asked many times before, but I never found a satisfying answer.

The problem:


I have to simulate a process scheduler, using the round robin strategy. I'm using threads to simulate processes and multiprogramming; everything works fine with the JVM managing the threads. But the thing is that now I want to have control of all the threads so that I can run each thread alone by a certain quantum (or time), just like real OS processes schedulers.

What I'm thinking to do:

I want have a list of all threads, as I iterate the list I want to execute each thread for their corresponding quantum, but as soon the time's up I want to pause that thread indefinitely until all threads in the list are executed and then when I reach the same thread again resume it and so on.

The question:

So is their a way, without using deprecated methods stop(), suspend(), or resume(), to have this control over threads?

© Stack Overflow or respective owner

Related posts about thread

Related posts about threads