mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Make cached executor service static
This commit is contained in:
parent
abdfe73006
commit
a4ab6245f6
1 changed files with 12 additions and 13 deletions
|
@ -33,6 +33,7 @@ import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
|
@ -242,16 +243,15 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
* A cached thread pool executor service with custom thread factory to set meaningful names on the threads and set
|
* A cached thread pool executor service with custom thread factory to set meaningful names on the threads and set
|
||||||
* them 'daemon'.
|
* them 'daemon'.
|
||||||
*/
|
*/
|
||||||
private final ExecutorService cachedExecutorService = Executors.newCachedThreadPool(
|
private static final ExecutorService CACHED_EXECUTOR_SERVICE = Executors.newCachedThreadPool(new ThreadFactory() {
|
||||||
// @formatter:off
|
@Override
|
||||||
// CHECKSTYLE:OFF
|
public Thread newThread(Runnable runnable) {
|
||||||
new SmackExecutorThreadFactory( // threadFactory
|
Thread thread = new Thread(runnable);
|
||||||
this,
|
thread.setName("Smack Cached Executor");
|
||||||
"Cached Executor"
|
thread.setDaemon(true);
|
||||||
)
|
return thread;
|
||||||
// @formatter:on
|
}
|
||||||
// CHECKSTYLE:ON
|
});
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A executor service used to invoke the callbacks of synchronous stanza(/packet) listeners. We use a executor service to
|
* A executor service used to invoke the callbacks of synchronous stanza(/packet) listeners. We use a executor service to
|
||||||
|
@ -1141,7 +1141,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
executorService = singleThreadedExecutorService;
|
executorService = singleThreadedExecutorService;
|
||||||
break;
|
break;
|
||||||
case async:
|
case async:
|
||||||
executorService = cachedExecutorService;
|
executorService = CACHED_EXECUTOR_SERVICE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
final IQRequestHandler finalIqRequestHandler = iqRequestHandler;
|
final IQRequestHandler finalIqRequestHandler = iqRequestHandler;
|
||||||
|
@ -1404,7 +1404,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
// reference to their ExecutorService which prevents the ExecutorService from being
|
// reference to their ExecutorService which prevents the ExecutorService from being
|
||||||
// gc'ed. It is possible that the XMPPConnection instance is gc'ed while the
|
// gc'ed. It is possible that the XMPPConnection instance is gc'ed while the
|
||||||
// listenerExecutor ExecutorService call not be gc'ed until it got shut down.
|
// listenerExecutor ExecutorService call not be gc'ed until it got shut down.
|
||||||
cachedExecutorService.shutdown();
|
|
||||||
removeCallbacksService.shutdownNow();
|
removeCallbacksService.shutdownNow();
|
||||||
singleThreadedExecutorService.shutdownNow();
|
singleThreadedExecutorService.shutdownNow();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
@ -1681,7 +1680,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void asyncGo(Runnable runnable) {
|
protected final void asyncGo(Runnable runnable) {
|
||||||
cachedExecutorService.execute(runnable);
|
CACHED_EXECUTOR_SERVICE.execute(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit) {
|
protected final ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit) {
|
||||||
|
|
Loading…
Reference in a new issue