Scheduling asynchronous tasks in Java Play 2.4.2: scala Duration compilation error -


i'm using akka system scheduler in play 2.4.2 execute asynchronous task. docs use scala.concurrent.duration.duration class create unit of time, getting compilation error says cannot create instance of duration because abstract class.

this block of code want execute asynchronously:

akka.system().scheduler().scheduleonce(no_delay, workerhandler, akka.system().dispatcher()); 

no_delay defined so:

private static final duration no_delay = new duration.create(0, "seconds");

and relevant import statements:

import scala.concurrent.duration.*; import java.util.concurrent.timeunit; 

the error message:

scala.concurrent.duration.duration abstract; cannot instantiated [error] new duration(0, "seconds") 

any ideas how use duration properly?

you cannot instanciate duration since abstract class, need drop new keyword.

therefore, can do:

import scala.concurrent.duration.duration;  private static final duration no_delay = duration.create(0, timeunit.seconds); 

or even:

private static final duration no_delay = duration.zero(); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -