So what's the best way to pause a thread? So far I have something like this: In main loop of the thread, first line is:
while (paused == true) {
Thread.sleep(refreshRate);
}
And it works perfercly. I can change paused state pressing P key. But Im looking for better, more professional solution. I know about reentrant locks and conditions. So I could use them on the thread. And then presing P would release singalAll() method. But it would slow my app a lot because of synchronization which I don't really need in this thread. So what is the best, most perform way to solve it? Maybe using synchronization blocks?
synchronized (new Object()) {
}
Then just part of code would be synchronized. Or maybe I should use semaphores?