Skip to content

Commit 3184d64

Browse files
huynmgHuy Nguyen
andauthored
Move numDocsIndexed.getAndIncrement into synchronized block (#386)
Co-authored-by: Huy Nguyen <[email protected]>
1 parent 0d36dc1 commit 3184d64

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/main/knn/IndexerThread.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,15 @@ public void run() {
7474
}
7575

7676
private void _run() throws IOException {
77-
int docsIndexed = 0;
7877
while (true) {
79-
int id = numDocsIndexed.getAndIncrement();
80-
if (id >= numDocsToIndex) {
81-
// yay, done!
82-
break;
83-
}
84-
78+
int id;
8579
Document doc = new Document();
8680
synchronized (vectorReader) {
81+
id = numDocsIndexed.getAndIncrement();
82+
if (id >= numDocsToIndex) {
83+
// yay, done!
84+
break;
85+
}
8786
switch (vectorEncoding) {
8887
case BYTE -> {
8988
byte[] bytes = ((VectorReaderByte) vectorReader).nextBytes();

0 commit comments

Comments
 (0)