views:

93

answers:

1

Someone helping me with a hung Java server studied the thread dump and does not understand the following state :

INFO   | jvm 1    | 2009/08/30 18:11:46 | "103468119@qtp-2047706572-1" prio=10 tid=0x0000000041758000 nid=0x13d7 waiting on condition [0x00007f6dbb75e000]
INFO   | jvm 1    | 2009/08/30 18:11:46 |    java.lang.Thread.State: RUNNABLE
INFO   | jvm 1    | 2009/08/30 18:11:46 |     at java.net.PlainSocketImpl.isConnectionReset(PlainSocketImpl.java:602)
INFO   | jvm 1    | 2009/08/30 18:11:46 |     - locked  (a java.lang.Object)

The code is running in

java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)

Indeed, according to the PlainSocketImpl source code, it should be impossible to stay a long time in the isConnectionReset() method even with the inner synchronization :

public boolean isConnectionReset() {
   synchronized (resetLock) {
      return (resetState == CONNECTION_RESET);
   }
}

Anyway, if the thread was blocked by the lock, its state would be BLOCKED. A thread in the state RUNNABLE "waiting on condition" means that the thread is waiting on an internal VM conditions variable.

A: 

There are an infinite number of ways to create the situation you describe, but the general theme is "two or more locks acquired in different orders".

 |  other thread                    your thread
 | 
 |  acquire resetLock                    x 
 |      x                                x
t|      x                         acquire fooLock
i|      x                                x
m|  attempt to acquire fooLock           x
e|  BLOCKED                              x
 |                                       x
 |                                       x 
 |                             attempt to acquire resetLock
 |                                     BLOCKED  <-- your dump
 |    
 v
Jonathan Feinberg
Yes, but how would I write code to get into a lock order conflict with an internal lock of the socket system?
bmargulies