0
import java.util.Timer;
import java.util.TimerTask;

class Test {
  boolean in_state;
}
class Processor {
  Timer timer;
  Test test;
  Processor(Test test) {
    this.test = test;
    init();
  }
  private init() {
    this.timer = new Timer();
    this.timer.schedule(new ProcessTask(), 0, 1000/20);
  }
  private class ProcessTask extends TimerTask {
      public void run() {
        if(test.in_state) {
          return;//skip
        }
        test.in_state = true;//start flag
        if(meetsCondition()) {
         //process possibly longer
         //make sure next scheduled task execution is delayed/skipped during until this task execution is finished
        }
        test.in_state = false;//end flag
      }
    }
 }

確認する必要があるのは、Process Task の次の実行が、前のタスクが終了したときに発生することです (meetsCondition() が発生すると時間がかかります)。

フィードバックをお寄せいただきありがとうございます。

4

0 に答える 0