All the tutorials that I have read work like this:
class HelloWorldActor extends Actor {
def receive = {
case "Hello" => self.reply("World")
}
}
val myActor = system.actorOf(Props[MyActor], name = "myactor")
I am wondering if AKKA supports the act() function inside an Actor class like this:
class HelloWorldActor extends Actor {
def act() = {
}
}
And then you can call:
val myActor = new HelloWorldActor
myActor.start()
I want to do this because my actor won’t be receieving any messages. It just works on its own. So can I use the act() function inside my AKKA actor?
In Akka, your actor should start automatically after creation using the system. But it sounds as if you want to use the actor like a plain thread we all know from Java. I would say that this is not the right way from an idiomatic point of view. You can of course just add a start message to your actor, send it to the actor after creation, and do your processing in the handler. But perhaps you should consider using a plain thread or a Future instead of an actor if you do not want to react on any message?