Is synchronization within an HttpSession feasible?

前端 未结 9 711
再見小時候
再見小時候 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:07

    Using

    private static final Object LOCK = new Object();
    

    you are using the same lock for all sessions and it was the core reason for deadlock I did face. So every session in your implementation has the same race condition, which is bad.

    It needs change.

    Other suggested answer:

    Object mutex = session.getAttribute(SESSION_MUTEX_ATTRIBUTE);
    if (mutex == null) {
      mutex = session;
    }
    return mutex;
    

    seems much better.

提交回复
热议问题