diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateProductionData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateProductionData.java index 6a080b96280..44bdefde9b2 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateProductionData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateProductionData.java @@ -139,8 +139,8 @@ public static void main(String[] args) { // get directories Arrays.asList(DtdType.values()) - //.parallelStream() - //.unordered() + .parallelStream() + .unordered() .forEach(type -> { boolean isLdmlDtdType = type == DtdType.ldml; @@ -154,6 +154,7 @@ public static void main(String[] args) { copyFilesAndReturnIsEmpty(sourceDir, destinationDir, null, isLdmlDtdType, stats); } }); + // should be called from the main thread. Synchronizing to document. if (!localeToSubdivisionsToMigrate.isEmpty()) { System.err.println("WARNING: Subdivision files not written, " + localeToSubdivisionsToMigrate.size() + " entries\n" + "For locales: " + localeToSubdivisionsToMigrate.keySet()); @@ -229,7 +230,7 @@ private static boolean copyFilesAndReturnIsEmpty(File sourceFile, File destinati final Factory theFactory = factory; final boolean isLdmlDtdType2 = isLdmlDtdType; sorted - //.parallelStream() + .parallelStream() .forEach(file -> { File sourceFile2 = new File(sourceFile, file); File destinationFile2 = new File(destinationFile, file); @@ -333,7 +334,9 @@ private static boolean copyFilesAndReturnIsEmpty(File sourceFile, File destinati // Move subdivisions elsewhere if (!isSubdivisionDirectory && xpath.startsWith("//ldml/localeDisplayNames/subdivisions/subdivision")) { - localeToSubdivisionsToMigrate.put(localeId, Pair.of(xpath, value)); + synchronized(localeToSubdivisionsToMigrate) { + localeToSubdivisionsToMigrate.put(localeId, Pair.of(xpath, value)); + } toRemove.add(xpath); continue; } @@ -377,12 +380,14 @@ private static boolean copyFilesAndReturnIsEmpty(File sourceFile, File destinati try (PrintWriter pw = new PrintWriter(destinationFile)) { CLDRFile outCldrFile = cldrFileUnresolved.cloneAsThawed(); if (isSubdivisionDirectory) { - Collection> path_values = localeToSubdivisionsToMigrate.get(localeId); - if (path_values != null) { - for (Pairpath_value : path_values) { - outCldrFile.add(path_value.getFirst(), path_value.getSecond()); + synchronized (localeToSubdivisionsToMigrate) { + Collection> path_values = localeToSubdivisionsToMigrate.get(localeId); + if (path_values != null) { + for (Pairpath_value : path_values) { + outCldrFile.add(path_value.getFirst(), path_value.getSecond()); + } + localeToSubdivisionsToMigrate.removeAll(localeId); } - localeToSubdivisionsToMigrate.removeAll(localeId); } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/LogicalGrouping.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/LogicalGrouping.java index c92c6b6088a..e2302cfeaf0 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/LogicalGrouping.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/LogicalGrouping.java @@ -55,7 +55,7 @@ public class LogicalGrouping { /** * Cache from path (String) to logical group (Set) */ - private static Multimap cachePathToLogicalGroup = ArrayListMultimap.create(); + private static final ConcurrentHashMap> cachePathToLogicalGroup = new ConcurrentHashMap<>(); /** * Cache from locale and path (), to logical group (Set) @@ -156,7 +156,13 @@ public static Set getPaths(CLDRFile cldrFile, String path, Output set = new TreeSet<>(); pathType.addPaths(set, cldrFile, path, parts); - cachePathToLogicalGroup.putAll(path, set); + cachePathToLogicalGroup.compute(path, (pathKey, cachedPaths) -> { + if (cachedPaths == null) { + return Collections.synchronizedSet(new HashSet<>(set)); + } else { + cachedPaths.addAll(set); + return cachedPaths; + }}); return set; } }