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();
}
}