我无法进入回调方法(onResult)并且闩锁正在等待无休止。
任何人都可以帮我解决这个问题...... 我的代码:
public void asyncWriteToMongoForMultiThreaded(String name, List<WriteModel<Document>> documentList, String colName,
String status) throws Exception {
final CountDownLatch bulkLatch = new CountDownLatch(1);
SingleResultCallback<BulkWriteResult> updateBatchResult = new SingleResultCallback<BulkWriteResult>() {
@Override
public void onResult(final BulkWriteResult result, final Throwable t) {
try {
updateStatusForThreads("abc", name, result.getInsertedCount(), status);
System.out.println(result +" "+ t);
} catch (Exception e) {
e.printStackTrace();
}
bulkLatch.countDown();
}
};
ConnectionManager cm = new ConnectionManager();
com.mongodb.async.client.MongoDatabase mongoDatabase = cm.getAsyncMongoClient();
com.mongodb.async.client.MongoCollection<Document> collection = mongoDatabase.getCollection(colName);
try{
collection.bulkWrite(documentList,updateBatchResult);
}catch (Exception e) {
e.printStackTrace();
}
bulkLatch.await();
}