sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Make code a little bit more type safe.
Date Wed, 08 Apr 2020 12:53:44 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new d7d7b7f  Make code a little bit more type safe.
d7d7b7f is described below

commit d7d7b7f9b57b2b87ab43ffe8c407f65845655c9a
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Apr 8 14:51:18 2020 +0200

    Make code a little bit more type safe.
---
 .../sis/internal/coverage/j2d/TileOpExecutor.java       |  4 ++--
 .../org/apache/sis/internal/system/CommonExecutor.java  | 17 +++++++++++++----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TileOpExecutor.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TileOpExecutor.java
index 5224ca9..5eaa015 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TileOpExecutor.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TileOpExecutor.java
@@ -871,7 +871,7 @@ public class TileOpExecutor {
             final Cursor<RenderedImage,A> cursor = executor.new Cursor<>(source,
collector, errorHandler == null);
             final Future<?>[] workers = new Future<?>[cursor.getNumWorkers()];
             for (int i=0; i<workers.length; i++) {
-                workers[i] = CommonExecutor.INSTANCE.submit(new ReadWork<>(cursor,
collector));
+                workers[i] = CommonExecutor.instance().submit(new ReadWork<>(cursor,
collector));
             }
             final ReadWork<A> worker = new ReadWork<>(cursor, collector);
             worker.run();
@@ -928,7 +928,7 @@ public class TileOpExecutor {
             final Cursor<WritableRenderedImage,A> cursor = executor.new Cursor<>(target,
collector, false);
             final Future<?>[] workers = new Future<?>[cursor.getNumWorkers()];
             for (int i=0; i<workers.length; i++) {
-                workers[i] = CommonExecutor.INSTANCE.submit(new WriteWork<>(cursor,
collector));
+                workers[i] = CommonExecutor.instance().submit(new WriteWork<>(cursor,
collector));
             }
             final WriteWork<A> worker = new WriteWork<>(cursor, collector);
             worker.run();
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/system/CommonExecutor.java
b/core/sis-utility/src/main/java/org/apache/sis/internal/system/CommonExecutor.java
index 7cfbd95..5e8085c 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/system/CommonExecutor.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/system/CommonExecutor.java
@@ -67,16 +67,25 @@ public final class CommonExecutor extends AtomicInteger implements ThreadFactory
      * or for JavaFX/Swing thread. In addition the caller will often do part of the work
in its own thread.
      * Threads are disposed after two minutes of inactivity.
      */
-    public static final ExecutorService INSTANCE;
+    private static final ThreadPoolExecutor INSTANCE;
     static {
         final ThreadPoolExecutor executor = new ThreadPoolExecutor(PARALLELISM, PARALLELISM,
2, TimeUnit.MINUTES,
-            new LinkedBlockingQueue<>(1000000),             // Arbitrary limit against
excessive queue expansion.
-            new CommonExecutor());
+                new LinkedBlockingQueue<>(1000000),         // Arbitrary limit against
excessive queue expansion.
+                new CommonExecutor());
         executor.allowCoreThreadTimeOut(true);
         INSTANCE = executor;
     }
 
     /**
+     * Returns the executor service shared by SIS modules for most costly calculations.
+     *
+     * @return the executor service for SIS tasks to run in background.
+     */
+    public static ExecutorService instance() {
+        return INSTANCE;
+    }
+
+    /**
      * If the given task has been scheduled for execution but its execution did not yet started,
      * removes it from the scheduled list. Otherwise does nothing. The given task should
be one
      * of the following values:
@@ -93,7 +102,7 @@ public final class CommonExecutor extends AtomicInteger implements ThreadFactory
      */
     public static boolean unschedule(final Object task) {
         if (task instanceof Runnable) {
-            return ((ThreadPoolExecutor) INSTANCE).remove((Runnable) task);
+            return INSTANCE.remove((Runnable) task);
         }
         return false;
     }


Mime
View raw message