Skip to content

Instantly share code, notes, and snippets.

@natalan
Forked from kdabir/README.md
Last active August 29, 2015 14:04
Show Gist options
  • Save natalan/7d069770a2605eb677c0 to your computer and use it in GitHub Desktop.
Save natalan/7d069770a2605eb677c0 to your computer and use it in GitHub Desktop.

Creating a TimerTask can not get easier than this thanks to groovy.

  • import java.util.timer.* is not required as java.util is already imported.
  • the run() is implemented as closure

To Run this:

groovy https://gist.github.com/kdabir/3176945/raw/timer_example.groovy

def timer = new Timer()
def task = timer.runAfter(10000) {
println "Actually executed at ${new Date()}."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment