Avoid deadlock on close (JAVA-418).