For example, one class has a private db, and a public method-put
.
We got several threads to run the put
, is this ok ? (ps: we don't consider the order of the k/v )
void put(List<byte[] keys, List<byte[]> values) {
WriteOptions writeOpt = new WriteOptions();
WriteBatch batch = new WriteBatch();
for (int i = 0; i < keys.size(); ++i) {
batch.put(keys.get(i), values.get(i));
}
this.db.write(writeOpt, batch);
}
The doc here says that
However other objects (like Iterator and WriteBatch) may require external synchronization.
If two threads share such an object, they must protect access to it using their own locking protocol.
But for the example above, the threads don't share the same WriteBatch
, they own its own WriteBatch
, and write to the db. So I wonder if this is ok?