timer - Java TimerTask cancel -
i have following problem. every 2 seconds programm go inside if statement. inside if statement want have timer give me message after 15 seconds. timer should run delay of 1 second. while i'm "waiting" timer, if statement executed 7 times. problem is, have 7 same timertask @ same time running. how can solve problem?
if (response == true) { final timer timer = new timer(); final int keepalivetimeout = 15000; //15 seconds timer.schedule(new timertask() { @override public void run() { if (response) { response = false; log.i(tag, "********response******"); timeoutcounter = 0; } else if (timeoutcounter > keepalivetimeout) { log.i(tag, "********timer timeout******"); } log.i(tag, "********timer******"); timeoutcounter = timeoutcounter + 1000; } }, 0, 1000); }
from java api:
public void schedule(timertask task, long delay, long period)
schedules specified task repeated fixed-delay execution, beginning after specified delay. subsequent executions take place @ approximately regular intervals separated specified period.
which means run task without delay, executed every second
@admin
ReplyDeleteThese are the values that we hold central to our practice. We create beautiful smiles as we focus on the overall health of your mouth. We encourage you to call or email us with any questions or concerns that you have so that we can better serve you.
Regards,
Dentist In unionville, CT
@admin
ReplyDeleteThese are the values that we hold central to our practice. We create beautiful smiles as we focus on the overall health of your mouth. We encourage you to call or email us with any questions or concerns that you have so that we can better serve you.
Regards,
Dentist In unionville, CT
@admin
ReplyDeleteWe provide all the requirements around the patients to give friendly involvement with divine and relaxed circumstances. Book an appointment and visit our clinic for our effective doctor’s experiences
Regards,
Dentist In Dracut, MA
@admin
ReplyDeleteWhen you visit for the first time in our clinic it means your first step to getting to know each other. In the time when we ask questions, we also try to listen to you and find the problem behind any problem and share with us anything you want us.
Regards,
Dentist In Wallingford, CT