Is there a special way for Scala to execute periodic execution?

AKA does something at set intervals.

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

In Java, I would use ScheduledExecutorService:

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

and it works great.

The fact is that I would like to try using Scala actors in my program, but I'm a little confused about how to combine Java participants and artists, or they should be.

Maybe I can have a simple runner who just sends a message to the actor every N seconds - does that make sense?

+5
source share
2 answers

Maybe I can have a simple runner who just sends a message to the actor every N seconds - does that make sense?

, , , . API, .

+2

Scala Executor , Java.

, java.lang.Runnable.
, , , ..
Executor . , new Thread(new(RunnableTask())).start() :

 Executor executor = anExecutor;
 executor.execute(new RunnableTask1());
 executor.execute(new RunnableTask2());
 ...
0

All Articles