Browse Source

Fix deadlock when reconnecting

Fixes issue 3704

Change-Id: I10590167a97e86d3abb21addbf3880d7e2dc97ac
Reviewed-on: http://gerrit.dmdirc.com/789
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.3b1
Chris Smith 14 years ago
parent
commit
a7cc5c0d87
2 changed files with 14 additions and 11 deletions
  1. 5
    7
      src/com/dmdirc/Server.java
  2. 9
    4
      src/com/dmdirc/ServerStatus.java

+ 5
- 7
src/com/dmdirc/Server.java View File

@@ -135,12 +135,12 @@ public class Server extends WritableFrameContainer implements
135 135
     /** The profile we're using. */
136 136
     private transient Identity profile;
137 137
 
138
-    /** The current state of this server. */
139
-    private final ServerStatus myState = new ServerStatus(this);
140
-
141
-    /** Object used to synchronoise access to myState. */
138
+    /** Object used to synchronise access to myState. */
142 139
     private final Object myStateLock = new Object();
143 140
 
141
+    /** The current state of this server. */
142
+    private final ServerStatus myState = new ServerStatus(this, myStateLock);
143
+
144 144
     /** The timer we're using to delay reconnects. */
145 145
     private Timer reconnectTimer;
146 146
 
@@ -262,9 +262,7 @@ public class Server extends WritableFrameContainer implements
262 262
                 case DISCONNECTING:
263 263
                     while (!myState.getState().isDisconnected()) {
264 264
                         try {
265
-                            synchronized (myState) {
266
-                                myState.wait();
267
-                            }
265
+                            myStateLock.wait();
268 266
                         } catch (InterruptedException ex) {
269 267
                             return;
270 268
                         }

+ 9
- 4
src/com/dmdirc/ServerStatus.java View File

@@ -39,6 +39,9 @@ public class ServerStatus {
39 39
     /** The server to which this status belongs. */
40 40
     protected final Server server;
41 41
 
42
+    /** Object to notify when the state of the server changes. */
43
+    protected final Object notifier;
44
+
42 45
     /** The current state of the server. */
43 46
     protected ServerState state = ServerState.DISCONNECTED;
44 47
 
@@ -52,10 +55,12 @@ public class ServerStatus {
52 55
      * Creates a new ServerStatus instance for the specified server.
53 56
      *
54 57
      * @param server The server to which this status belongs
55
-     * @since 0.6.3m2
58
+     * @param notifier The object to notify when the state changes
59
+     * @since 0.6.3
56 60
      */
57
-    public ServerStatus(final Server server) {
61
+    public ServerStatus(final Server server, final Object notifier) {
58 62
         this.server = server;
63
+        this.notifier = notifier;
59 64
     }
60 65
 
61 66
     /**
@@ -69,8 +74,8 @@ public class ServerStatus {
69 74
         if (state.canTransitionTo(newState)) {
70 75
             state = newState;
71 76
 
72
-            synchronized (this) {
73
-                notifyAll();
77
+            synchronized (notifier) {
78
+                notifier.notifyAll();
74 79
             }
75 80
         } else {
76 81
             throw new IllegalArgumentException("Illegal server state "

Loading…
Cancel
Save