Simple cron like scheduler in Scala
Today in my Scala explorations I ran into the problem that I wanted some scheduler like Quarz or java.util.Timer -- that should be easy in scala I thought an came up with the following:
private val timedActor = actor {
//once a day
while (true) {
performTask
val c = Calendar.getInstance
c.set(Calendar.HOUR_OF_DAY, 0) //midnight
c.set(Calendar.MINUTE,0)
c.add(Calendar.DAY_OF_YEAR, 1) //next day
val sleepAmount = c.getTimeInMillis - Calendar.getInstance.getTimeInMillis
Thread.sleep(sleepAmount)
}
}
Pretty