且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Playframework 1.x静态方法如何以线程安全的方式工作

更新时间:2022-12-30 22:18:42

是的,我们还不错.如您所知,HTTP是无状态的,因此请求之间不会共享任何内容.在处理请求时,播放使用ThreadLocal.每个请求都有其自己的线程,因此您可以完全控制当前请求-响应生命周期.

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.

如果要在控制器之间共享数据,则可以使用session对象,但是该对象很小,并且仅接受String个对象.对于其他数据类型或共享的不同实现,应使用Cache实现.有关更多信息,请参见会话

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.

祝你好运!