mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
Make scheduled executor service static
This commit is contained in:
parent
cd05d5f5d8
commit
4f88f23f33
1 changed files with 19 additions and 5 deletions
|
@ -79,6 +79,7 @@ import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
||||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||||
import org.jivesoftware.smack.provider.ProviderManager;
|
import org.jivesoftware.smack.provider.ProviderManager;
|
||||||
import org.jivesoftware.smack.sasl.core.SASLAnonymous;
|
import org.jivesoftware.smack.sasl.core.SASLAnonymous;
|
||||||
|
import org.jivesoftware.smack.util.Async;
|
||||||
import org.jivesoftware.smack.util.DNSUtil;
|
import org.jivesoftware.smack.util.DNSUtil;
|
||||||
import org.jivesoftware.smack.util.Objects;
|
import org.jivesoftware.smack.util.Objects;
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
|
@ -238,8 +239,16 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
/**
|
/**
|
||||||
* This scheduled thread pool executor is used to remove pending callbacks.
|
* This scheduled thread pool executor is used to remove pending callbacks.
|
||||||
*/
|
*/
|
||||||
private final ScheduledExecutorService removeCallbacksService = Executors.newSingleThreadScheduledExecutor(
|
protected static final ScheduledExecutorService SCHEDULED_EXECUTOR_SERVICE = Executors.newSingleThreadScheduledExecutor(
|
||||||
new SmackExecutorThreadFactory(this, "Remove Callbacks"));
|
new ThreadFactory() {
|
||||||
|
@Override
|
||||||
|
public Thread newThread(Runnable runnable) {
|
||||||
|
Thread thread = new Thread(runnable);
|
||||||
|
thread.setName("Smack Scheduled Executor Service");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -1407,7 +1416,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.
|
||||||
removeCallbacksService.shutdownNow();
|
|
||||||
singleThreadedExecutorService.shutdownNow();
|
singleThreadedExecutorService.shutdownNow();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
LOGGER.log(Level.WARNING, "finalize() threw trhowable", t);
|
LOGGER.log(Level.WARNING, "finalize() threw trhowable", t);
|
||||||
|
@ -1560,7 +1568,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
} else {
|
} else {
|
||||||
exception = NoResponseException.newWith(AbstractXMPPConnection.this, replyFilter);
|
exception = NoResponseException.newWith(AbstractXMPPConnection.this, replyFilter);
|
||||||
}
|
}
|
||||||
exceptionCallback.processException(exception);
|
final Exception exceptionToProcess = exception;
|
||||||
|
Async.go(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
exceptionCallback.processException(exceptionToProcess);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, timeout, TimeUnit.MILLISECONDS);
|
}, timeout, TimeUnit.MILLISECONDS);
|
||||||
|
@ -1687,6 +1701,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit) {
|
protected final ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit) {
|
||||||
return removeCallbacksService.schedule(runnable, delay, unit);
|
return SCHEDULED_EXECUTOR_SERVICE.schedule(runnable, delay, unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue