Reputation: 1
i am trying to execute a method every minute using akka. although i am getting no errors but the method is never executed!! i tried to extend play.api.globalsettings but i got an error for that. so i implemented it.
here is my code:
public class Global implements play.api.GlobalSettings {
ActorRef tickActor;
@Override
public void beforeStart(Application app) {
}
@Override
public void onStart(play.api.Application app) {
{
Akka.system().scheduler().schedule(
Duration.create(0, TimeUnit.MILLISECONDS),
Duration.create(1, TimeUnit.MINUTES),
new Runnable() {
public void run() {
Secured securedObject = new Secured();
securedObject.deleteExpiredTokensAndUsers();
}
},
Akka.system().dispatcher()
);
}
any idea?
Upvotes: 0
Views: 397
Reputation: 1
thanks dribba, got it solved. here is my code:
import controllers.Secured;
import play.Application;
import play.GlobalSettings;
import play.libs.Akka;
import scala.concurrent.duration.Duration;
import java.util.concurrent.TimeUnit;
/**
* Created by Admin on 4/3/14.
*/
public class Global extends GlobalSettings {
@Override
public void onStart(Application application) {
Akka.system().scheduler().schedule(
Duration.create(0, TimeUnit.SECONDS),
Duration.create(5, TimeUnit.MINUTES),
new Runnable() {
@Override
public void run() {
Secured.deleteExpiredTokensAndUsers();
}
},
Akka.system().dispatcher()
);
}
}
Upvotes: 0
Reputation: 56
In a java application you should extend from play.GlobalSettings and not play.api.GlobalSettings
In Play Framework 2 for a Java application you should use the framework's play package, and for a Scala application you use the play.api package. They may have a lot of classes in common but they are not the same.
Upvotes: 2