Skip to content

Instantly share code, notes, and snippets.

@166MMX
Forked from kdabir/README.md
Created June 16, 2013 22:50
Show Gist options
  • Save 166MMX/5793752 to your computer and use it in GitHub Desktop.
Save 166MMX/5793752 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 count = 0
new Timer().schedule({
println count++
} as TimerTask, 1000, 3000) //magic numbers are initial-delay & repeat-interval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment