Skip to content

Commit ff70133

Browse files
committed
Optimize deleteUrlList by replacing CopyOnWriteArrayList with ArrayList
Changed deleteUrlList from CopyOnWriteArrayList to ArrayList since all access is already protected by synchronized(indexUpdateCallback) blocks. CopyOnWriteArrayList creates a copy on every write operation which is unnecessary overhead when synchronization is already in place. Changes: - Replaced CopyOnWriteArrayList with ArrayList for deleteUrlList - Added synchronized block in commit() method for consistency - Updated javadoc to clarify synchronization strategy This improves performance for batch delete operations by eliminating unnecessary array copying on each URL addition.
1 parent 4177e8e commit ff70133

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/java/org/codelibs/fess/ds/callback/FileListIndexUpdateCallbackImpl.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Map;
2626
import java.util.Objects;
2727
import java.util.Set;
28-
import java.util.concurrent.CopyOnWriteArrayList;
2928
import java.util.concurrent.ExecutorService;
3029
import java.util.concurrent.LinkedBlockingQueue;
3130
import java.util.concurrent.ThreadPoolExecutor;
@@ -90,8 +89,11 @@ public class FileListIndexUpdateCallbackImpl implements IndexUpdateCallback {
9089
/** Factory for creating crawler clients to handle different URL schemes. */
9190
protected CrawlerClientFactory crawlerClientFactory;
9291

93-
/** List of URLs to be deleted, cached for batch processing. Thread-safe using CopyOnWriteArrayList. */
94-
protected List<String> deleteUrlList = new CopyOnWriteArrayList<>();
92+
/**
93+
* List of URLs to be deleted, cached for batch processing.
94+
* All access is synchronized via indexUpdateCallback lock.
95+
*/
96+
protected List<String> deleteUrlList = new ArrayList<>();
9597

9698
/** Maximum size of the delete URL cache before batch deletion is triggered. */
9799
protected int maxDeleteDocumentCacheSize;
@@ -586,8 +588,10 @@ public void commit() {
586588
executor.shutdownNow();
587589
}
588590

589-
if (!deleteUrlList.isEmpty()) {
590-
deleteDocuments();
591+
synchronized (indexUpdateCallback) {
592+
if (!deleteUrlList.isEmpty()) {
593+
deleteDocuments();
594+
}
591595
}
592596
indexUpdateCallback.commit();
593597
}

0 commit comments

Comments
 (0)