sleep other Thread
in
Programming Questions
•
1 year ago
(first sorry, my tabs dissapear sometimes on pasting stuff to this board)
I have a class called CustomProgram that does NOT run on a Thread.
I also have a class TL_ProgramCommunicator that DOES run on a Thread.
In CustomProgram i have this for example:
- void programLoad() {
- println("a");
- clearBlack();
- waitToBeReady();
- println("b");
- clearWhite();
- waitToBeReady();
- println("c");
- clearBlack();
- waitToBeReady();
- println("d");
- clearWhite();
- waitToBeReady();
- println("e");
- }
where waitToBeReady in CustomProgram looks like this:
- public void waitToBeReady() {
- if (programCommunicator != null) {
- programCommunicator.waitToBeReady();
- }
- }
And in TL_ProgramCommunicator (the one that run on it's own Thread) is as follow:
- public void waitToBeReady() {
- boolean ready = false;
- while (ready == false) {
- ready = field.update();
- try {
- sleep((long) (interval));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
That all works fine, unless i call waitToBeReady() from the main processing tab.
For example, if i make a method on the main processing tab:
- void debug() {
- println("a");
- currentProgram.clearBlack();
- currentProgram.waitToBeReady();
- println("b");
- currentProgram.clearWhite();
- currentProgram.waitToBeReady();
- println("c");
- currentProgram.clearBlack();
- currentProgram.waitToBeReady();
- println("d");
- currentProgram.clearWhite();
- currentProgram.waitToBeReady();
- println("e");
- }
And call that, then my processing freezes for certain time untill the other thread is done.
So looks like the wrong thread went to sleep.
How can i make the other Thread sleep from the processing Thread?
2