【发布时间】:2020-03-03 13:59:12
【问题描述】:
例如,一个类有一个私有数据库和一个公共方法-put。
我们有几个线程来运行put,这样可以吗? (ps:我们不考虑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);
}
doc here 这么说
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.
但是对于上面的示例,线程不共享相同的WriteBatch,它们拥有自己的WriteBatch,并写入数据库。所以我想知道这样可以吗?
【问题讨论】:
标签: java multithreading thread-safety rocksdb rocksdb-java