Skip to content

Instantly share code, notes, and snippets.

@nitsanw
Created May 16, 2013 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitsanw/5594570 to your computer and use it in GitHub Desktop.
Save nitsanw/5594570 to your computer and use it in GitHub Desktop.
Avoiding false sharing on JDK 6/7
// No false sharing on 6, but happens on 7
public final static class VolatileLong
{
public volatile long value = 0L;
public long p1, p2, p3, p4, p5, p6;
}
// No false sharing on 6 or 7
public static class PaddedAtomicLong extends AtomicLong
{
public volatile long p1, p2, p3, p4, p5, p6 = 7L;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment