Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

Are reads and writes of long and double atomic in Java? What about references and other primitives, and what is word tearing?

Not necessarily: the Java Language Specification allows a write to a non-volatile long or double to be split into two 32-bit writes, so another thread could read a value made of one new half and one old half. Declaring the field volatile makes its reads and writes atomic, and reads and writes of references and of every other primitive type are always atomic. Word tearing, where writing one field or array element damages its neighbour, is never allowed in Java.

Background to this question

This looks like a trivia question, but it tests whether we know the difference between what the Java specification promises and what our particular JVM happens to do. The difference matters whenever a plain field is shared between threads, which is common in counters, timestamps and status flags. In this answer, we will recap what atomic means for a single read or write, look at the special rule for long and double and why it exists, see how volatile changes it, check what holds for references and the other primitives, and finally explain word tearing and why Java forbids it.

1A Quick Recap of Atomic Reads and Writes

An action is atomic when other threads can only see it as complete or not done at all, never halfway. For a single field write, that means a reader sees either the old value or the new value, never some mixture of the two.

Atomicity of a single read or write is a narrower idea than thread safety. Even when each write is atomic, an operation such as count++ is a read followed by a write, and two threads can interleave between them. It is also separate from visibility, the question of when another thread sees the new value at all. This question is only about the first and smallest promise: is one read or one write indivisible?

2The Special Rule for long and double

Section 17.7 of the JLS says that a single write to a non-volatile long or double may be treated as two separate writes, one to each 32-bit half. The rule exists because Java was designed to run on 32-bit processors, where writing 64 bits at once was either impossible or expensive. Allowing two writes kept the language fast on that hardware.

So, in principle, a reader can see a value that nobody ever wrote.

Java
class Shared {
long value; // plain, non-volatile
}
// Thread 1 writes, starting from 0:
shared.value = 0xFFFF_FFFF_FFFF_FFFFL; // -1, all bits set
// Thread 2 reads at the same moment. Allowed outcomes by the JLS:
long seen = shared.value;
// 0x0000_0000_0000_0000L 0, the old value
// 0xFFFF_FFFF_FFFF_FFFFL -1, the new value
// 0xFFFF_FFFF_0000_0000L -4294967296, new high half, old low half
// 0x0000_0000_FFFF_FFFFL 4294967295, old high half, new low half

Notice that the last two values were never written by any thread. That is what non-atomic means here: the write was observed in two pieces.

3What volatile Changes

The JLS also says that writes and reads of volatile long and volatile double are always atomic. So the fix for the example above is one word.

Java
class Shared {
volatile long value; // reads and writes are now atomic
}
// Thread 2 can only ever see 0 or -1

volatile does more than that, which is usually the bigger reason to use it: a volatile write is visible to later volatile reads, and it creates a happens-before edge, so everything the writer did before the write is visible to a reader who sees the new value. AtomicLong gives the same atomic reads and writes, and adds atomic compound operations such as incrementAndGet().

4References and the Other Primitives

For everything else the answer is simple: reads and writes of references, and of boolean, byte, char, short, int and float, are always atomic, volatile or not. A thread reading a reference field sees either the old reference or the new one, never a corrupt pointer. That guarantee is part of what keeps Java memory-safe even when a program has data races.

Atomic does not mean visible or ordered, though. A plain int written by one thread may not be seen by another for a long time, and a plain reference may be seen before the fields of the object it points to are written. Those are visibility and ordering problems, solved by volatile, locks or final fields, not by atomicity.

Atomicity of a single read or write
Kind of fieldPlain fieldvolatile field
boolean, byte, char, short, int, floatatomicatomic, and visible to later reads
object referencesatomicatomic, and visible to later reads
long, doublemay be split into two 32-bit halvesatomic, and visible to later reads
Only plain long and double lack the atomicity guarantee in the JLS.

5What Happens in Practice on 64-bit JVMs

On a modern 64-bit JVM such as HotSpot on x86-64 or AArch64, a plain long field is almost always written with a single 64-bit instruction, so we will very likely never see a torn value. But that is a property of the implementation, not a promise of the language. Some 32-bit JVMs, embedded runtimes or unusual code generation may still split the write, and the specification allows it.

The JLS itself encourages implementations to avoid splitting and advises programmers to declare shared 64-bit values volatile or to synchronize. So the professional answer is to rely on the specification: if a long or double is shared between threads without a lock, make it volatile or use an atomic class.

6What Word Tearing Is and Why Java Forbids It

Word tearing is a different problem that sounds similar. Some processors cannot write a single byte; they can only write a whole word, such as 32 bits. To update one byte, the hardware or the compiler would have to read the whole word, change one byte and write the whole word back. If another thread updated a neighbouring byte in between, that update would be lost, even though the two threads touched different variables.

Section 17.6 of the JLS forbids this: every field and every array element is a separate variable, and updating one must never interfere with another. So two threads may safely write different elements of a byte array, each without a lock, and neither will corrupt the other.

Java
byte[] flags = new byte[2];
Thread a = new Thread(() -> { for (int i = 0; i < 1_000_000; i++) flags[0] = 1; });
Thread b = new Thread(() -> { for (int i = 0; i < 1_000_000; i++) flags[1] = 2; });
a.start(); b.start(); a.join(); b.join();
System.out.println(flags[0] + " " + flags[1]); // always 1 2: no word tearing in Java

So the two ideas are opposites in a way. Splitting one long into two halves is allowed for plain fields; merging writes to neighbouring variables is never allowed.

7Follow-up questions

Is a non-volatile boolean flag safe for stopping a thread?

The write itself is atomic, so the other thread will never see a corrupt value, but it may never see the new value at all. The JIT may read the field once and reuse the value in a loop. The flag must be volatile, or read and written under a lock, for the stop to be seen reliably.

Does AtomicLong give anything more than a volatile long?

For a single read or a single write, they behave the same. AtomicLong adds atomic read-modify-write operations, such as incrementAndGet(), compareAndSet() and accumulateAndGet(), which a volatile long cannot do because count++ on a volatile field is still a separate read and write.

Can a torn long happen on HotSpot today?

It is very unlikely on 64-bit HotSpot, because the generated code writes 64-bit fields with one instruction. But the specification still permits it, and code that relies on the implementation is not portable to every JVM, so we still declare shared longs volatile.

8Conclusion

In this answer, we saw that the JLS lets a plain long or double write be split into two 32-bit halves, so a reader may see a value nobody wrote, while volatile long and double are always atomic. References and the other primitive types are always atomic. Most 64-bit JVMs write longs atomically anyway, but that is not guaranteed, so shared 64-bit values should be volatile or atomic. Finally, word tearing, where writing one variable corrupts a neighbour, is forbidden by the JLS for fields and array elements alike.

What to say in the interviewAbout 80 seconds aloud

Open with

Reads and writes of references and of all primitive types except long and double are always atomic. For long and double, the Java Language Specification allows a write to a non-volatile field to be done as two 32-bit writes, a rule that comes from 32-bit hardware.

Then, if they want more

So another thread could in principle see the high half of the new value and the low half of the old one. If the field is volatile, reads and writes of long and double are guaranteed to be atomic, and volatile also gives visibility and ordering.

On today's 64-bit JVMs a plain long is almost always written in one instruction, so tearing is unlikely in practice, but it is not guaranteed by the specification, so I would still declare a shared long volatile or use AtomicLong.

I would also point out that atomic is not the same as visible: even an atomic int can be stale without volatile. Word tearing is a different thing: it is when writing one variable, such as one byte of an array, corrupts a neighbouring variable because the hardware writes a whole word.

Java forbids that, so threads can safely write different array elements or fields without interfering with each other.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
JLS chapter 17, Threads and Locks
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Are reads and writes of long and double atomic in Java? What about references and other...": https://scrivio-interview-library.netlify.app/java/java-memory-model/e061692151/