mou
mou

Reputation: 73

How to make application to initialize before first request?

I have an application which i run from Intellij IDEA. In global object i have an onStart hook, which starts Akka jobs.

When i run this application it didn't initialize until i trigger request to one of controllers.

Is it possible to make framework initialize eagerly?

Upvotes: 3

Views: 181

Answers (1)

Daniel Olszewski
Daniel Olszewski

Reputation: 14401

Your solution is correct and will work in the production mode as desired. After the application is started, the onStart() method from your GlobalSettings implementation. is called before any request is served.

To facilitate development in the dev mode, it works slightly different and the framework restarts the server automatically after changes are made to the source code but does it only after the first request is made. Why? If the framework ware to restart every time code was updated, it would constantly rebooting. Hence, the first request is used as a trigger to start the process.

Upvotes: 4

Related Questions