Pause and resume a method

I am having some problems pausing and resuming a method. (Using Java in Eclipse).

I basically write a program that is a bit like a compiler. I give it a line and interpret this line, convert it to a block of n commands, conditions and things, such as loops (depending on the strong one) and execute these commands. For instance:

(while 
  (energy-at-least 1000)
  (seq
    (move) 
    (turn clockwise)
  )
)

I currently have a method that stops on the Nth command, but I'm not sure how to continue after that, since reusing this method and telling it to start with the Nth + 1 command, it forgets that the program is in a loop (s).

Sorry for the poor explanation, but basically I have to be able to stop this method on the Nth team and let it resume the course it followed. Java had methods for these (resume () and stop ()), but they are deprecated, I saw. Anyone have a good idea?

+3
source share
4 answers

From what I understand, your statement is that you need finer control over the loop in the stream, then methods such as “notify”, “resume”, etc. are suggested. You can do the following:

A stream class might look like this:

public WhateverLoop implements Runnable {
    private volatile boolean run = true;

    public void run() {
        while(run) {
            doWhatever();
        }        
    }

    public setRun(boolean run) {
        this.run = run;
    }
}

"" . "run" ( ). .

:

WhateverLoop whateverLoop = new WhateverLoop();
Thread WhateverLoopThread = new Thread(whateverLoop);
whateverLoopThread.start();
// Do stuff which consumes time.
...
// Stop the loop
whateverLoop.setRun(false);

, , , , ( ).

0

wait() notify(). , , , notify() , .

0

- , , , , "context".

, . , , .

, ...


- "", CLI ( , ). CLI "" , .

0
source

Did you think you control it with BlockingQueue?

Run it with a queue of N instructions to execute it. He will pull each team out of the queue and process it. As soon as he reaches the Nth command, he will stop / block. To start it again from where it left off, enter the queue for more instructions.

0
source

All Articles