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

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1804634 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2017-08-10 06:11:26 +00:00
parent 89eca637b8
commit d34d77bde3
@@ -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;
}
}