I have a method and I want it to be scheduled for execution in later times. The scheduling time and method\'s arguments depend on user inputs.
I already have tried T
class thr extends TimerTask{
@Override
public void run(){
System.out.println("task executed task executed .........." );
}
class service {
private Timer t;
public void start(int delay){
Timer timer=new Timer();
thr task =new thr();
timer.schedule(task, delay);
this.t=timer;
}
public void stop(){
System.out.println("Cancelling the task scheduller ");
this.t.cancel();
}
}
public class task1 {
public static void main(String[] args) {
service sv=new service();
sv.start(1000);
System.out.println("This will check the asynchronous behaviour ");
System.out.println("This will check the asynchronous behaviour ");
System.out.println("This will check the asynchronous behaviour ");
System.out.println("This will check the asynchronous behaviour ");
System.out.println("This will check the asynchronous behaviour ");
sv.stop();
}
}
the code above works fine to schedule and reschedule the task you can set and reset the task with a timer function