Scala web :: lazy val scope/lifetime

白昼怎懂夜的黑 提交于 2019-12-12 02:59:59

问题


In a Scala web application, is lazy val scoped to the lifetime of the application server, or request scoped?

I assume it is per request, but have not been able to find a definitive answer, thus the question.

Thanks


回答1:


lazy is a Scala feature, not related to web application programming. It means: evaluate only once on first access. If the variable is part of an object created per request, it will be lazily evaluated once per every request.

If it is declared inside application-wide class (or object), once evaluated it will keep its value as long as the class is loaded (so probably the WAR lifetime).



来源:https://stackoverflow.com/questions/10025567/scala-web-lazy-val-scope-lifetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!