Using request.getSession() as a locking object?

后端 未结 7 974
面向向阳花
面向向阳花 2020-12-11 02:18

I have some java code that gets and sets a session attribute:

Object obj = session.getAttribute(TEST_ATTR);
if (obj==null) {
  obj = new MyObject();
  sessio         


        
相关标签:
7条回答
  • 2020-12-11 03:10

    It is generally frowned upon to use a lock that you have no control over. A lock should be scoped as tightly as possible and since the session is more or less a global object, it does not fit the bill. Try to use a separate lock from the java.util.concurrent.locks package and scope it to your class.

    0 讨论(0)
提交回复
热议问题