changeset 1008:cf03638b6e73

Fix Swing Exceptions on connection failure I recently noticed that when starting the GUI without the agent running, sporadic exceptions would occur in Swing code. This seems to be caused by interleaving of two threads calling ConnectionHandler.changed. When DbService.connect fails to connect it throws a ConnectionException which was caught by Main.connect. In this catch clause, we are calling ConnectionHandler.changed, but at the same time the ConnectionListener fires. This causes the handler to be called twice from different threads. With this code removed, the sporadic exceptions no longer seem to occur. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-February/005901.html
author Elliott Baron <ebaron@redhat.com>
date Wed, 27 Feb 2013 12:53:18 -0500
parents 53ce942c35c1
children e053b0c2d48f
files client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java	Tue Feb 26 15:31:32 2013 -0500
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java	Wed Feb 27 12:53:18 2013 -0500
@@ -235,9 +235,9 @@
                     try {
                         dbService.connect();
                     } catch (Throwable t) {
+                        // Note: DbService fires a ConnectionListener event when it
+                        // fails to connect. No need to notify our handler manually.
                         logger.log(Level.WARNING, "connection attempt failed: ", t);
-                        // is this ever possible?
-                        reconnectionHandler.changed(ConnectionStatus.FAILED_TO_CONNECT);
                     }
                 }
             });