'What happens if you read from an unloaded MappedByteBuffer?
What happens if you read/write into MappedByteBuffer that is unloaded?
Will the operation fail? Will it read/write the underlying file more slowly than it would if the file was memory-mapped? Will it trigger a load() followed by the read/write?
The specification does not seem to indicate one way or another, but at the same time it doesn't indicate that get() and put() may throw an exception for this case so I'm not sure what to expect.
I would prefer an answer driven by the specification as opposed to peeking at the underlying source-code that may change in the future.
Solution 1:[1]
Re-reading the specification, isLoaded() does not indicate whether the file was "unmapped" but rather that the memory-map might have been swapped out.
So, assuming I understand this correctly, any subsequent reads/writes will trigger page faults which will reload the map into physical memory.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gili |
