user182944
user182944

Reputation: 8067

Play framework 1.2.5 application slow startup

I am using Play framework 1.2.5 and Hibernate 3.25 for developing my web application. I am facing problems with the application startup, it is very slow :(

For any Java EE servlet-driven application, we use the ServletContextListener for initializing the session factories (which is really a time consuming job). Once the application is deployed, the session factories will be initialized and all this have to be completed before the application is ready to use for the end user. In this way, when the user triggers the first request, the response time for the first is faster.

But, for Play framework does not follow any servlet architecture. Hence not sure how to implement something similar to the ServletContextListener which will be create all the session factories before the application is ready to use to the end user.

Without this, for the first time the application is really very slow for the first request.

I am sure there might be something in Play Framework also which will do the same but I am not aware of it.

Please let me know about this.

Upvotes: 1

Views: 1166

Answers (3)

emt14
emt14

Reputation: 4896

You can use a Job to initialise you application. For example you could have a bootstrap job annotated with @OnApplicationStart which would take care of loading your static data or initialising you cache or factories.

@OnApplicationStart
public class Bootstrap extends Job {

    public void doJob() {
        //Load static data
        //Initialise cache
        //Initialise factories
        ...
        // ready to serve application
    }
}

Upvotes: 3

Gelin Luo
Gelin Luo

Reputation: 14373

JB should be correct. In short you can start the server with --%prod option:

play run --%prod

or

play start --%prod

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691715

You're probably running the application in development mode, where everything is compiled and initialized lazily, on the first request. The production mode compiles everything before actually starting the server. See http://www.playframework.org/documentation/1.2.5/production

Upvotes: 1

Related Questions