svn commit: r1804634 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1804634 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java

jleroux@apache.org
Author: jleroux
Date: Thu Aug 10 06:11:26 2017
New Revision: 1804634

URL: http://svn.apache.org/viewvc?rev=1804634&view=rev
Log:
Improved: [FB] Package org.apache.ofbiz.base.concurrent
(OFBIZ-9562)

Fixes some diamond operators
Implementes equals method to fix potential problems
Implementes hashCode method because I implemented equals method
Implementes timeDiff method to keep the code DRY

Thanks: Dennis Balkir

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java?rev=1804634&r1=1804633&r2=1804634&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java Thu Aug 10 06:11:26 2017
@@ -41,7 +41,7 @@ import org.apache.ofbiz.base.util.Debug;
 @SourceMonitored
 public final class ExecutionPool {
     public static final String module = ExecutionPool.class.getName();
-    public static final ExecutorService GLOBAL_BATCH = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ExecutionPoolThreadFactory(null, "OFBiz-batch"));
+    public static final ExecutorService GLOBAL_BATCH = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, new SynchronousQueue<>(), new ExecutionPoolThreadFactory(null, "OFBiz-batch"));
     public static final ForkJoinPool GLOBAL_FORK_JOIN = new ForkJoinPool();
     private static final ExecutorService pulseExecutionPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new ExecutionPoolThreadFactory(null, "OFBiz-ExecutionPoolPulseWorker"));
 
@@ -77,7 +77,7 @@ public final class ExecutionPool {
     }
 
     public static <F> List<F> getAllFutures(Collection<Future<F>> futureList) {
-        List<F> result = new LinkedList<F>();
+        List<F> result = new LinkedList<>();
         for (Future<F> future: futureList) {
             try {
                 result.add(future.get());
@@ -105,7 +105,7 @@ public final class ExecutionPool {
         }
     }
 
-    private static final DelayQueue<Pulse> delayQueue = new DelayQueue<Pulse>();
+    private static final DelayQueue<Pulse> delayQueue = new DelayQueue<>();
 
     public static class ExecutionPoolPulseWorker implements Runnable {
         public void run() {
@@ -145,10 +145,32 @@ public final class ExecutionPool {
         }
 
         public final int compareTo(Delayed other) {
-            long r = (expireTimeNanos - ((Pulse) other).expireTimeNanos);
+            if (this.equals(other)) {
+                return 0;
+            }
+            long r = timeDiff((Pulse) other);
             if (r < 0) return -1;
-            if (r > 0) return 1;
-            return 0;
+            return 1;
+        }
+
+        public final boolean equals(Object other) {
+            if(other instanceof Pulse) {
+                return timeDiff((Pulse) other) == 0;
+            }
+            return false;
+        }
+
+        public int hashCode() {
+            return super.hashCode();
+        }
+
+        /**
+         * Calculates the difference between this.expireTimeNanos and other.expireTimeNanos
+         * @param other used to calculate the difference
+         * @return the time difference of the two instance's expireTimeNanos
+         */
+        public long timeDiff(Pulse other) {
+            return expireTimeNanos - other.expireTimeNanos;
         }
     }