Skip to content

Instantly share code, notes, and snippets.

@shijinkui
Created June 8, 2015 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shijinkui/bed3ac8c3eb75e91044c to your computer and use it in GitHub Desktop.
Save shijinkui/bed3ac8c3eb75e91044c to your computer and use it in GitHub Desktop.
package akka
import akka.actor.{Actor, ActorSystem, Props}
import scala.concurrent.duration._
object AkkaScheduleTest {
def main(args: Array[String]) {
val system = ActorSystem("akka_system")
system.actorOf(Props[AkkaScheduleTest], "test_actor")
}
}
class AkkaScheduleTest extends Actor {
import context._
override def preStart() = system.scheduler.scheduleOnce(500 millis, self, "init_schedule")
// override postRestart so we don't call preStart and schedule a new message
override def postRestart(reason: Throwable) = {}
override def receive: Actor.Receive = {
case "init_schedule" =>
// send another periodic tick after the specified delay
system.scheduler.scheduleOnce(1000 millis, self, AA())
case a: AA =>
println(a)
if (a.flag < 10)
system.scheduler.scheduleOnce(1000 millis, self, AA(a.flag + 1))
}
}
case class AA(flag: Int = 0, ct: Long = System.nanoTime())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment