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


Comments

  1. @admin

    These 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

    ReplyDelete
  2. @admin

    These 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

    ReplyDelete
  3. @admin

    We 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

    ReplyDelete
  4. @admin

    When 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

    ReplyDelete

Post a Comment

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -