1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 17:19:39 +02:00

Improve handling of InterruptedException

InterruptedExceptions should be treated as the users intention to
'cancel' the current thread's task. There is no such thing as a
spurious interrupt (not to be confused with "spurious wakeups").
This commit is contained in:
Florian Schmaus 2015-01-16 15:55:06 +01:00
parent 14b03149db
commit d099e7b16d
5 changed files with 15 additions and 11 deletions

View file

@ -156,13 +156,15 @@ public class ReconnectionManager {
}
}
catch (InterruptedException e) {
// We don't need to handle spurious interrupts, in the worst case, this will cause to
// reconnect a few seconds earlier, depending on how many (spurious) interrupts arrive while
// sleep() is called.
LOGGER.log(Level.FINE, "Supurious interrupt", e);
LOGGER.log(Level.FINE, "waiting for reconnection interrupted", e);
break;
}
}
for (ConnectionListener listener : connection.connectionListeners) {
listener.reconnectingIn(0);
}
// Makes a reconnection attempt
try {
if (isReconnectionPossible(connection)) {

View file

@ -248,7 +248,8 @@ public class Roster {
}
}
catch (InterruptedException e) {
LOGGER.log(Level.FINE, "spurious interrupt", e);
LOGGER.log(Level.FINE, "interrupted", e);
break;
}
long now = System.currentTimeMillis();
waitTime -= now - start;

View file

@ -201,7 +201,6 @@ public class DummyConnection extends AbstractXMPPConnection {
return (P) queue.poll(wait, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
// TODO handle spurious interrupts
throw new IllegalStateException(e);
}
}

View file

@ -49,7 +49,6 @@ public class WaitForPacketListener implements PacketListener {
}
}
catch (InterruptedException e) {
// TODO better handling of spurious interrupts
throw new IllegalStateException(e);
}
}