1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-26 12:37:58 +01:00

Shutdown listenerExecutor to prevent the Thread from leaking

listenerExecutor needs to get shutdown once it is no longer required.

SMACK-567
This commit is contained in:
Florian Schmaus 2014-05-21 13:02:32 +02:00
parent f1f7713513
commit f4f7eca7ca

View file

@ -1318,4 +1318,19 @@ public abstract class XMPPConnection {
public FromMode getFromMode() {
return this.fromMode;
}
@Override
protected void finalize() throws Throwable {
try {
// It's usually not a good idea to rely on finalize. But this is the easiest way to
// avoid the "Smack Listener Processor" leaking. The thread(s) of the executor have a
// reference to their ExecutorService which prevents the ExecutorService from being
// 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.shutdownNow();
}
finally {
super.finalize();
}
}
}