5 Replies Latest reply on Feb 8, 2017 1:37 AM by Seto Kaiba

    How can I ensure the data is modified correctly?

    Seto Kaiba Expert

      I have two thread trying to modify a queue in the cache.

      The 1st is reading the queue, adding object to it and putting back .

      The 2nd is reading the queue, polling object from it, and putting back. And it's a iterative operation.


      Now, the 2nd overwrite the adding operation from 1st.

      Because the 2nd read the old queue. And overwrite it.

      I want to avoid the 2nd reading the queue, while the 1st modifying the queue.

      I can't use thread lock. Because the cache is distributed clustered.


      How can I avoid the overwrite by threads?

      Which transaction should I use, pessimistic or optimistic?

      I tried both it seems that both are committed without any exception thrown.