[Spread-users] remove/disconnect appears to deadlock in Java (4.0.0RC2)

Doug Palmer Doug.Palmer at csiro.au
Tue Aug 15 02:17:12 EDT 2006

When attempting to shut down a SpreadConnection in Java I seem to be
running into trouble with


If I do this, then the disconnect often locks up. Instead, I have to
write something like

Thread.sleep(2000); // Give it a chance to shut down

Looking at a deadlock dump from the JVM, I see

[java] "AWT-EventQueue-0" prio=1 tid=0x09b4fb90 nid=0x7319 waiting for
monitor entry [0xb117d000..0xb117e1c0]
[java]     at
[java]     - waiting to lock <0x88f74f28> (a spread.SpreadConnection)
[java]     at

[java] "Thread-4" daemon prio=1 tid=0x09a212a8 nid=0x7315 in
Object.wait() [0xb155a000..0xb155afc0]
[java]     at java.lang.Object.wait(Native Method)
[java]     - waiting on <0x88f77200> (a spread.SpreadConnection
[java]     at java.lang.Thread.join(Thread.java:1095)
[java]     - locked <0x88f77200> (a spread.SpreadConnection$Listener)
[java]     at java.lang.Thread.join(Thread.java:1148)
[java]     at
[java]     at spread.SpreadConnection.remove(SpreadConnection.java:1532)
[java]     - locked <0x88f76010> (a java.lang.Boolean)
[java]     at spread.SpreadConnection
[java]     - locked <0x88f74f28> (a spread.SpreadConnection)


[java] "Thread-0" daemon prio=1 tid=0x09a06b08 nid=0x7311 runnable
[java]     at java.net.SocketInputStream.socketRead0(Native Method)
[java]     at
[java]     at
[java]     at spread.SpreadConnection.access
[java]     at spread.SpreadConnection
[java]     - locked <0x88f5fd28> (a java.lang.Boolean)
[java]     - locked <0x88f5ca28> (a spread.SpreadConnection)

So it would appear that the disconnect process deadlocks with two
threads trying to get a lock on the SpreadConnection object.

It would seem to me that part of the problem is that socket reads from a
stream block and you want to interrupt the read. The java.nio.* classes
allow non-blocking reads and writes. Is there some reason why spread
doesn't use java.nio?

More information about the Spread-users mailing list