Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 103149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:04:40+00:00 2026-05-11T01:04:40+00:00

For years and years, I’ve tried to understand the part of Java specification that

  • 0

For years and years, I’ve tried to understand the part of Java specification that deals with memory model and concurrency. I have to admit that I’ve failed miserably. Yes’ I understand about locks and ‘synchronized’ and wait() and notify(). And I can use them just fine, thank you. I even have a vague idea about what ‘volatile’ does. But all of that was not derived from the language spec – rather from general experience.

Here are two sample questions that I am asking. I am not so much interested in particular answers, as I need to understand how the answers are derived from the spec (or may be how I conclude that the spec has no answer).

  • What does ‘volatile’ do, exactly?
  • Are writes to variable atomic? Does it depend on variable’s type?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:04:41+00:00Added an answer on May 11, 2026 at 1:04 am

    I’m not going to attempt to actually answer your questions here – instead I’ll redirect you to the book which I seeing recommended for advice on this topic: Java Concurrency in Practice.

    One word of warning: if there are answers here, expect quite a few of them to be wrong. One of the reasons I’m not going to post details is because I’m pretty sure I’d get it wrong in at least some respects. I mean no disrespect whatsoever to the community when I say that the chances of everyone who thinks they can answer this question actually having enough rigour to get it right is practically zero. (Joe Duffy recently found a bit of the .NET memory model that was surprised by. If he can get it wrong, so can mortals like us.)


    I will offer some insight on just one aspect, because it’s often misunderstood:

    There’s a difference between volatility and atomicity. People often think that an atomic write is volatile (i.e. you don’t need to worry about the memory model if the write is atomic). That’s not true.

    Volatility is about whether one thread performing a read (logically, in the source code) will ‘see’ changes made by another thread.

    Atomicity is about whether there is any chance that if a change is seen, only part of the change will be seen.

    For instance, take writing to an integer field. That is guaranteed to be atomic, but not volatile. That means that if we have (starting at foo.x = 0):

    Thread 1: foo.x = 257; Thread 2: int y = foo.x; 

    It’s possible for y to be 0 or 257. It won’t be any other value, (e.g. 256 or 1) due to the atomicity constraint. However, even if you know that in ‘wall time’ the code in thread 2 executed after the code in thread 1, there could be odd caching, memory accesses ‘moving’ etc. Making the variable x volatile will fix this.

    I’ll leave the rest up to real honest-to-goodness experts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Years ago, I have heard that someone was about to demonstrate that every computer
For years I have been using the DEBUG compiler constant in VB.NET to write
Several years back, I innocently tried to write a little app to save my
Years ago I had seen a tool that when running would allow you to
10 years have ellapsed since I used COM/OLE, and I forget 90% of them.
For years I've been reading about XML and I have just not quite grokked
Years back I built a simple mail form that has been working like a
For years now I've been using a chat that has the following code to
Many years back, I was told that Javascript was harmful, and I remember being
2 years ago I red on jamesward's blog http://www.jamesward.com/blog/2007/11/12/oracle-chooses-flex-part-1/ something about oracle uses flex

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.