0
我的應用程序需要在應用程序啓動時獲取一些資源包。我希望應用程序等待這些資源被加載,並且在該加載完成之前不會提供任何請求。所以我基本上想要好的老的java阻止行爲。因此,我嘗試在我的應用程序的單例對象Global
中的單元方法beforeStart
中放置一些阻塞行爲。如何延遲應用程序啓動以執行一些初始化?
object Global extends GlobalSettings {
override def onStart(app: Application) {
Logger.info("begin: Global.onStart")
val resourcesFetched = ResourceService.fetchResourceBundles()
import scala.concurrent.duration._
Await.result(resourcesFetched, 30.second)
Logger.info("end: Global.onStart")
}
}
這種方法目前適用於我,但它看起來很尷尬。有沒有其他的鉤子我應該使用?我沒有在文檔中找到合適的東西。