actorakka.net

How to put actor to sleep?


I have one actor which is executing a forever loop that is waiting for the availability of data to operate on. The doc says the Actor runs on a very lightweight thread, so I'm not sure whether i can use the thread.sleep() method on that actor. My objective is to not have that actor consume too much processing power.

So can I use the thread.sleep() method inside the actor ?


Solution

  • Don't sleep() inside Actors! That would cause the Thread to be blocked, causing exactly what you're trying to avoid - using up resources.

    Instead if you just handle the message and "do nothing", the Actor will not use up any scheduling resources and will be just another plain object on the heap (occupying around a bit of memory but nothing else).