Is synchronization within an HttpSession feasible?

前端 未结 9 715
再見小時候
再見小時候 2020-12-04 14:47

UPDATE: Solution right after question.

Question:

Usually, synchronization is serializing parallel requests within a JVM, e.

9条回答
  •  天命终不由人
    2020-12-04 15:21

    In general, don't rely on HttpServletRequest.getSession() returning same object. It's easy for servlet filters to create a wrapper around session for whatever reason. Your code will only see this wrapper, and it will be different object on each request. Put some shared lock into the session itself. (Too bad there is no putIfAbsent though).

提交回复
热议问题