1. 创建并启用模块
1 2 3 4 5 6
| public class ZTasksModule extends AbstractModule { @Override protected void configure() { bind(CompositeImageTask.class).asEagerSingleton(); } }
|
2. 然后在application.conf中通过添加以下行来启用该模块
play.modules.enabled += "tasks.ZTasksModule"
3. 任务demo CompositeImageTask.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public class CompositeImageTask { private final ActorSystem actorSystem; private final ExecutionContext executionContext;
@Inject public CompositeImageTask(ActorSystem actorSystem, ExecutionContext executionContext) { this.actorSystem = actorSystem; this.executionContext = executionContext; this.initialize(); }
private void initialize() { this.actorSystem.scheduler().schedule( Duration.create(1, TimeUnit.MINUTES), Duration.create(10, TimeUnit.MINUTES), () -> composite(), this.executionContext ); }
public void composite() { } }
|