Announcement Announcement Module
Collapse
No announcement yet.
Why so volatile Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why so volatile

    I've read some of the source code, and wonder why you've used volatile in so many places.
    I know it is a basic part of Java, and I can google what it does.
    What I want to know is what were your (the spring integration developers) reasons for using?
    What did you observe that indicated it was necessary?

  • #2
    I think the best way to answer this question is to check out this book http://www.amazon.com/gp/product/032...SIN=0321349601

    The short answer is to ensure that in the multithreaded execution environment, the updates to the variable are visible immediately to all threads. In other words with various JVM optimization if current value of variable 'a' is let's say is set to 0 and Thread 1 changes it to 1, Thread 2 might still see it as 0. The 'volatile' keyword ensures that all writes to the variable go to main memory (not cached thread-locally).
    But as I said, this only scratches the surface, there is more and reading the above would help.

    Comment

    Working...
    X