简体   繁体   English

播放框架1.2.5应用程序启动缓慢

[英]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. 我正在使用Play框架1.2.5和Hibernate 3.25来开发我的Web应用程序。 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). 对于任何Java EE servlet驱动的应用程序,我们使用ServletContextListener来初始化会话工厂(这实际上是一项耗时的工作)。 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. 但是,对于Play框架并不遵循任何servlet架构。 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. 因此不确定如何实现类似于ServletContextListener东西,它将在应用程序准备好用于最终用户之前创建所有会话工厂。

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. 我相信Play Framework中也可能会有相同的内容,但我不知道。

Please let me know about this. 请让我知道这件事。

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注释引导作业,该引导作业将负责加载静态数据或初始化缓存或工厂。

@OnApplicationStart
public class Bootstrap extends Job {

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

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 http://www.playframework.org/documentation/1.2.5/production

JB should be correct. JB应该是正确的。 In short you can start the server with --%prod option: 简而言之,您可以使用--%prod选项启动服务器:

play run --%prod

or 要么

play start --%prod

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM