How Playframework 1.x static method works in a thread safe way

妖精的绣舞 提交于 2019-12-11 11:38:47

问题


Might be a silly question, but I'm noob learning Play framework 1.2.5. I've noticed that the controller actions are all static methods and I assume each request will be processed in a separate thread. If that's the case, how Play framework ensures these static controller methods are thread safe? I think, as long as we are not sharing anything between controller methods then we are good (?), please correct me if I'm wrong.

Thanks in advance.


回答1:


Yes we're quite good. As you know HTTP is stateless, so nothing will be shared between requests. Play uses ThreadLocals while processiong the request. Each request has it's own thread so you have full control of the current request - response life cycle.

If you want to share data between controllers, you have session object however it's quite small and accepts only Strings. For other data types or different implementations of sharing, you should use a Cache implementation. For further information see session and cache documentations.

Good luck!



来源:https://stackoverflow.com/questions/16110757/how-playframework-1-x-static-method-works-in-a-thread-safe-way

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