diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java b/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java index d576f50fe8..dd7151160c 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/concurrent/ExecutionPool.java @@ -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(), 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 List getAllFutures(Collection> futureList) { - List result = new LinkedList(); + List result = new LinkedList<>(); for (Future future: futureList) { try { result.add(future.get()); @@ -105,7 +105,7 @@ public final class ExecutionPool { } } - private static final DelayQueue delayQueue = new DelayQueue(); + private static final DelayQueue 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; } }