Repository navigation
Expand file tree
/
Copy pathSharedData.java
More file actions
56 lines (42 loc) · 2.11 KB
/
Copy pathSharedData.java
File metadata and controls
56 lines (42 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.*;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicInteger;
// Container for all shared resources and global state used by worker threads
public class SharedData {
// Buffer for all articles read from JSON files before duplicate processing.
public static List<Article> rawArticles = new LinkedList<>();
// Final list of unique articles after filtering and sorting
public static List<Article> validArticles;
// Aggregated results for output generation
public static List<ResultInfo> globalCatPairs = new LinkedList<>();
public static List<ResultInfo> globalLangPairs = new LinkedList<>();
public static List<String> globalKeywords = new LinkedList<>();
// Configuration lists loaded from files
public static LinkedList<String> targetLanguages;
public static LinkedList<String> targetCategories;
// Optimized Set for fast O(1) lookups during text processing
public static HashSet<String> stopWords;
public static List<String> inputJsonFiles;
// Synchronization barrier to coordinate processing stages
public static CyclicBarrier barrier;
// Atomic counters for dynamic load balancing
public static AtomicInteger fileIndex = new AtomicInteger(0);
public static AtomicInteger articleIndex = new AtomicInteger(0);
public static int duplicatesFound = 0;
// Thread-safe method to merge local thread results into the global raw list
public static synchronized void addRawArticles(List<Article> localList) {
rawArticles.addAll(localList);
}
// Thread-safe method to aggregate category mappings
public static synchronized void addGlobalCatPairs(List<ResultInfo> localList) {
globalCatPairs.addAll(localList);
}
// Thread-safe method to aggregate language mapping
public static synchronized void addGlobalLangPairs(List<ResultInfo> localList) {
globalLangPairs.addAll(localList);
}
// Thread-safe method to aggregate extracted keywords
public static synchronized void addGlobalKeywords(List<String> localList) {
globalKeywords.addAll(localList);
}
}