0

I have class (MC) and there is a timer inside it to perform a task several times. After finishing, I want to go back to the original class (Main) without retaining MC class.

if I call method (afterFinishingMC) from MC I'm concern there could be recursive stack pilling up.

This is my code:

public class Menu {
    private mc = new MC();

    public void main(String[] args) {
        mc.begin();
    }

    Public void afterFinishingMC() {
        //code here
    }
}

//MC class
import java.util.Timer;
import java.util.TimerTask;

public class MC {
    public Timer timer = new Timer();

    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            //code here
        }
    };

    public void begin {
        timer.schedule(task, 1000, 1000);
    }

    public void interrupt {
        timer.cancel(); 
    }
}
Andres F.
  • 403
  • 1
  • 13
  • 24
HJC
  • 3
  • 3
  • 2
    your code even compile, please edit it, but you can use observer pattern.. – nachokk Jul 20 '13 at 00:57
  • 1
    Firstly, I see no recursion here. Secondly, the timer runs in a separate thread. Please be more specific about what your concern is. – Aurand Jul 20 '13 at 01:00
  • nachokk: Why are you trying to compile it? The original code is very long but this is to give you an idea about the problem. – HJC Jul 20 '13 at 01:15
  • Aurand: I know that timer runs in a separate thread. My question if I called afterFinishingMC() from inside MC it is going to be waiting for afterFinishingMC() to finish and then return to MC. I do not want to return to MC. – HJC Jul 20 '13 at 01:19
  • What does `afterFinishingMC()` have to do MC? Why does it matter? It's defined in another class, and makes no reference to MC. Can you provide a better code snippet, showing what you're actually trying to do? – Andres F. Jul 20 '13 at 01:30
  • Andres: MC collects 4 types of data consecutively with a timeout for each data input. After, I want to execute afterFinishingMC() which deals the the collected data. – HJC Jul 20 '13 at 01:40

0 Answers0