Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Scala-specific way to implement periodic execution?

AKA doing something at set intervals.

For example, let's say I want to scan a certain directory every 60 seconds.

In Java, I would use a ScheduledExecutorService like so:

Executor pool = Executors.newScheduledThreadPool(10)
pool.scheduleAtFixedRate(scanner, 0, 60, TimeUnit.SECONDS)

and that works fine.

The thing is, I'm thinking I'd like to try using Scala actors in my program, but I'm a little confused as to how to combine actors and Java Executors, or whether they should be.

I guess maybe I could have a simple runner which would merely send a message to an actor every N seconds -- does that make sense?

like image 271
Avi Flax Avatar asked Nov 05 '22 11:11

Avi Flax


1 Answers

I guess maybe I could have a simple runner which would merely send a message to an actor every N seconds -- does that make sense?

Yes, and consider using Akka for the Actors by the way. It has a simpler API, better performance and has a lot of yummy stuff in it.

like image 109
olle kullberg Avatar answered Nov 17 '22 08:11

olle kullberg