0

My application invokes the following timer task from another class OnStart right away, one of the problems I'm trying to avoid is having the the next task invoked before the first one is done. How do I approach this?

import ratpack.server.Service
import ratpack.server.StartEvent
import ratpack.server.StopEvent
import java.util.timer.*

class FTPPoller implements Service {

    @Override
    void onStart(StartEvent event) throws Exception {
        println 'Hey, I started'
        new Timer().schedule({FTPlisten.FTPdownload("localhost", "*****", "*****")} as TimerTask, 1000, 5000)
    }
}
tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • Where are you getting `Timer` from? Can you show your imports? – tim_yates May 17 '16 at 15:29
  • 1
    @tim_yates `import ratpack.server.Service` `import ratpack.server.StartEvent` `import ratpack.server.StopEvent` `import groovy.transform.Field` `import java.util.timer.*` – Mohamed Ashmawy May 17 '16 at 15:32
  • Added to the question. So I think you want [to use this](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html#scheduleWithFixedDelay-java.lang.Runnable-long-long-java.util.concurrent.TimeUnit-). See [this question](http://stackoverflow.com/questions/24649842/scheduleatfixedrate-vs-schedulewithfixeddelay) for an explanation – tim_yates May 17 '16 at 15:37
  • I can see how [this](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html#scheduleWithFixedDelay-java.lang.Runnable-long-long-java.util.concurrent.TimeUnit-) might help, but it doesn't answer my question on how to block the next task if the first task still hasn't finished. – Mohamed Ashmawy May 17 '16 at 15:46
  • I don't believe you do, you just have a scheduler with one thread and then schedule with a fixed delay – tim_yates May 17 '16 at 16:01

0 Answers0