首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >每天使用Akka运行任务的框架

每天使用Akka运行任务的框架
EN

Stack Overflow用户
提问于 2014-09-26 12:57:47
回答 2查看 1.5K关注 0票数 1

我正在寻找简单的例子/手册/使用Aktor在PlayFramework与Java。我已经尝试过这个教程:https://www.playframework.com/documentation/2.2.x/JavaAkka,但我无法使它编译。

我想在每24户统计一些数据,并发送电子邮件从系统。我想用它,阿克托。

我使用playFramework 2.2.x

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-09-29 08:19:02

我的工作解决方案(针对playFramework 2.2.4)基于post:https://stackoverflow.com/a/14706767/1066240

我在/app/Global.java中的Global.java类

代码语言:javascript
运行
复制
import org.joda.time.DateTime;
import org.joda.time.Seconds;

import actions.ValidateApplicationLicence;
import akka.actor.ActorRef;
import akka.actor.Props;
import play.Application;
import play.GlobalSettings;
import play.Logger;
import play.libs.Akka;
import scala.concurrent.duration.Duration;

import java.util.concurrent.TimeUnit;

public class Global extends GlobalSettings {

    //ActorRef myActor = Akka.system().actorOf(new Props(ValidateApplicationLicence.class));

    @Override
    public void onStart(Application application) {

        Akka.system().scheduler().schedule(
                Duration.create(20, TimeUnit.SECONDS),
                Duration.create(5, TimeUnit.SECONDS),
                new Runnable() {
                    @Override
                    public void run() {
                        Logger.info("After 10 sec and after EVERY 5 sec  ---    " + controllers.common.Index.getDate(null));
                    }
                },
                Akka.system().dispatcher()
        );

        Akka.system().scheduler().scheduleOnce(
                Duration.create(10, TimeUnit.MILLISECONDS),
                new Runnable() {
                    public void run() {
                        Logger.info("ON START ---    " + controllers.common.Index.getDate(null));
                    }
                },
                Akka.system().dispatcher()
        );
//      Akka.system().scheduler().schedule(
//                Duration.create(0, TimeUnit.MILLISECONDS), //Initial delay 0 milliseconds
//                Duration.create(30, TimeUnit.MINUTES),     //Frequency 30 minutes
//                myActor,
//                "tick",
//                Akka.system().dispatcher(),
//                null
//        );
    }
    public static int nextExecutionInSeconds(int hour, int minute){
        return Seconds.secondsBetween(
                new DateTime(),
                nextExecution(hour, minute)
        ).getSeconds();
    }

    public static DateTime nextExecution(int hour, int minute){
        DateTime next = new DateTime()
                .withHourOfDay(hour)
                .withMinuteOfHour(minute)
                .withSecondOfMinute(0)
                .withMillisOfSecond(0);

        return (next.isBeforeNow())
                ? next.plusHours(24)
                : next;
    }
}
票数 2
EN

Stack Overflow用户

发布于 2014-09-26 14:47:11

有一个用于Play 2.0.4 in Java的示例,无论如何,在2.1中有几件事情发生了更改(主要是导入)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26060170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档