Closed georgeto closed 9 years ago
This scenario occured during execution of the JsonTest, but I'm pretty sure it is also possible in a real enviroment.
To understand this problem, it is important to know, that Selector.selectNow() synchronizes on Selector, Selector.keys() and Selector.selectedKeys().
public int selectNow() throws IOException { return lockAndDoSelect(0); } private int lockAndDoSelect(long timeout) throws IOException { synchronized (this) { if (!isOpen()) throw new ClosedSelectorException(); synchronized (publicKeys) { synchronized (publicSelectedKeys) { return doSelect(timeout); } } } }
[Thread 1]
Client.update()
selector
connection.sendTCP()
[Thread 2]
Client.stop()
Client.close()
updateLock
selector.selectNow()
Client.sendTCP()
This scenario occured during execution of the JsonTest, but I'm pretty sure it is also possible in a real enviroment.
To understand this problem, it is important to know, that Selector.selectNow() synchronizes on Selector, Selector.keys() and Selector.selectedKeys().
[Thread 1]
Client.update()
locksselector
connection.sendTCP()
[Thread 2]
Client.stop()
is called, and callsClient.close()
Client.close()
closes the tcp connectionClient.close()
grabsupdateLock
Client.close()
callsselector.selectNow()
, and waits for [Thread 1] to unlockselector
[Thread 1]
Client.sendTCP()
throws an IOException and callsClient.close()
Client.close()
waits for [Thread 2] to unlockupdateLock