diff --git a/indexer/src/main/java/au/org/aodn/esindexer/utils/GeometryUtils.java b/indexer/src/main/java/au/org/aodn/esindexer/utils/GeometryUtils.java index 1a48344d..74c49650 100644 --- a/indexer/src/main/java/au/org/aodn/esindexer/utils/GeometryUtils.java +++ b/indexer/src/main/java/au/org/aodn/esindexer/utils/GeometryUtils.java @@ -23,6 +23,7 @@ import java.math.RoundingMode; import java.net.URL; import java.util.*; +import java.util.concurrent.*; import java.util.function.Function; public class GeometryUtils { @@ -271,7 +272,8 @@ protected static List convertToListGeometry(Geometry multipolygon) { * @param large - A Polygon to break into grid * @return - A polygon the break into grid. */ - protected static List breakLargeGeometryToGrid(Geometry large) { + protected static List breakLargeGeometryToGrid(final Geometry large) { + logger.debug("Start break down large geometry"); // Get the bounding box (extent) of the large polygon Envelope envelope = large.getEnvelopeInternal(); @@ -279,14 +281,42 @@ protected static List breakLargeGeometryToGrid(Geometry large) { // cover Australia List gridPolygons = createGridPolygons(envelope, getCellSize()); - List intersectedPolygons = new ArrayList<>(); + // Create an ExecutorService with a fixed thread pool size + ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + + // List to store Future objects representing the results of the tasks + List> futureResults = new ArrayList<>(); + + // Submit tasks to executor for each gridPolygon for (Polygon gridPolygon : gridPolygons) { - Geometry intersection = gridPolygon.intersection(large); - if (!intersection.isEmpty()) { - intersectedPolygons.add(intersection); + Callable task = () -> { + Geometry intersection = gridPolygon.intersection(large); + return !intersection.isEmpty() ? intersection : null; + }; + Future future = executorService.submit(task); + futureResults.add(future); + } + + // List to store the intersected polygons + final List intersectedPolygons = new ArrayList<>(); + + // Collect the results from the futures + for (Future future : futureResults) { + try { + // This blocks until the result is available + Geometry result = future.get(); + if (result != null) { + intersectedPolygons.add(result); + } + } catch (InterruptedException | ExecutionException e) { + // Nothing to report } } + // Shutdown the ExecutorService after all tasks are completed + executorService.shutdown(); + + logger.debug("End break down large geometry"); return intersectedPolygons; } diff --git a/indexer/src/main/resources/application-edge.yaml b/indexer/src/main/resources/application-edge.yaml index c49f45a9..7a1b6803 100644 --- a/indexer/src/main/resources/application-edge.yaml +++ b/indexer/src/main/resources/application-edge.yaml @@ -9,3 +9,7 @@ management: web: exposure: include: "health,info,env,beans,logfile" + +logging: + level: + au.org.aodn.ardcvocabs: DEBUG \ No newline at end of file