1

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.

4

3 回答 3

3

您可以使用 Job 来初始化您的应用程序。例如,您可以有一个使用@OnApplicationStart注释的引导作业,该作业将负责加载您的静态数据或初始化您的缓存或工厂。

@OnApplicationStart
public class Bootstrap extends Job {

    public void doJob() {
        //Load static data
        //Initialise cache
        //Initialise factories
        ...
        // ready to serve application
    }
}
于 2013-01-27T10:57:50.790 回答
1

您可能在开发模式下运行应用程序,在第一次请求时,所有内容都被懒惰地编译和初始化。生产模式在实际启动服务器之前编译所有内容。见http://www.playframework.org/documentation/1.2.5/production

于 2013-01-27T08:53:37.603 回答
0

JB应该是正确的。简而言之,您可以使用以下--%prod选项启动服务器:

play run --%prod

或者

play start --%prod
于 2013-01-27T10:19:35.950 回答