Created
June 8, 2015 06:26
-
-
Save shijinkui/bed3ac8c3eb75e91044c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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