From cb27b02658d004d5e5e214f6f91619477b535789 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 10 May 2018 19:36:11 +0200 Subject: [PATCH] Make SmackFuture use Smack's cached executor service instead of SmackFuture using it's own executor service. --- .../org/jivesoftware/smack/SmackFuture.java | 38 +------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackFuture.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackFuture.java index 78b55b2c6..88a951677 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackFuture.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackFuture.java @@ -16,15 +16,9 @@ */ package org.jivesoftware.smack; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; -import java.util.concurrent.RejectedExecutionHandler; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -145,41 +139,13 @@ public abstract class SmackFuture implements Future, return getOrThrowExecutionException(); } - private static final ExecutorService EXECUTOR_SERVICE; - - static { - ThreadFactory threadFactory = new ThreadFactory() { - @Override - public Thread newThread(Runnable r) { - Thread thread = new Thread(r); - thread.setDaemon(true); - thread.setName("SmackFuture Thread"); - return thread; - } - }; - BlockingQueue blockingQueue = new ArrayBlockingQueue<>(128); - RejectedExecutionHandler rejectedExecutionHandler = new RejectedExecutionHandler() { - @Override - public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { - r.run(); - } - }; - int cores = Runtime.getRuntime().availableProcessors(); - int maximumPoolSize = cores <= 4 ? 2 : cores; - ExecutorService executorService = new ThreadPoolExecutor(0, maximumPoolSize, 60L, TimeUnit.SECONDS, - blockingQueue, threadFactory, rejectedExecutionHandler); - - EXECUTOR_SERVICE = executorService; - } - - @SuppressWarnings("FutureReturnValueIgnored") protected final synchronized void maybeInvokeCallbacks() { if (cancelled) { return; } if (result != null && successCallback != null) { - EXECUTOR_SERVICE.submit(new Runnable() { + AbstractXMPPConnection.asyncGo(new Runnable() { @Override public void run() { successCallback.onSuccess(result); @@ -187,7 +153,7 @@ public abstract class SmackFuture implements Future, }); } else if (exception != null && exceptionCallback != null) { - EXECUTOR_SERVICE.submit(new Runnable() { + AbstractXMPPConnection.asyncGo(new Runnable() { @Override public void run() { exceptionCallback.processException(exception);