0

There are multiple put methods for java.nio.FloatBuffer. As far as I know, most (all?) of them depend on an internal state of the buffer, so they are not thread-safe. My question is if this also applies for the following method?

public abstract FloatBuffer put(int index, float f)

The documentation says:

Absolute put method (optional operation).

Writes the given float into this buffer at the given index.

In my case at hand it would be no problem if an update is lost/overwritten from time to time, but it would be fatal if a write happened on a completely different index (because the internal position is overwritten before the value is put or something like that).

Community
  • 1
  • 1
schreon
  • 1,097
  • 11
  • 25
  • The method is `abstract`, it depends on the implementation –  Oct 29 '14 at 15:50
  • 1
    [`Buffer`](http://docs.oracle.com/javase/7/docs/api/java/nio/Buffer.html) says: *"Buffers are not safe for use by multiple concurrent threads. If a buffer is to be used by more than one thread then access to the buffer should be controlled by appropriate synchronization."* There are at least visibility problems if one thread writes to an absolute position and another one reads the data. – zapl Oct 29 '14 at 16:01
  • A `FloatBuffer` might be a [view into a `ByteBuffer`](http://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html#asFloatBuffer()) so there is not even a guaranty that this modification is atomic. It might consist of four byte updates. – Holger Oct 31 '14 at 14:16

0 Answers0