Ghijs Kilani
Ghijs Kilani

Reputation: 166

Continuously-running code in Java Play! Framework

In the Play!-framework, code is triggered by requesting a URL from the server. The thing is, I need to have some code in the background running continuously from start-up, polling a database for new entries every few minutes, as if it were a normal program with a main() function. As far as I can tell the only way to run code is to navigate to a URL, but that's not what I want here. Any way to accomplish this?

Upvotes: 1

Views: 92

Answers (1)

biesior
biesior

Reputation: 55798

Sounds like you want to use some kind of cron task (correct me if I'm wrong)

In Play 2.x it's done with Akka's scheduler mentioned in the docs

Even more informations and/or samples you can find on the original Akka's docs

In general: in Play you can just schedule some task in the onStart() method of the Global class and then repeat in desired duration as long as required.

Edit: of course Akka is built-in the Play 2.x from the very beginning, actually we could say that Play is built on top of the Akka ;)

Upvotes: 1

Related Questions