diff -r 86d46701261b -r 2ed6188288d6 jdk/src/share/classes/sun/nio/ch/AbstractPollSelectorImpl.java --- a/jdk/src/share/classes/sun/nio/ch/AbstractPollSelectorImpl.java Fri Oct 10 10:58:08 2008 +0200 +++ b/jdk/src/share/classes/sun/nio/ch/AbstractPollSelectorImpl.java Mon Oct 13 14:45:27 2008 -0700 @@ -58,6 +58,9 @@ // True if this Selector has been closed private boolean closed = false; + // Lock for close and cleanup + private Object closeLock = new Object(); + AbstractPollSelectorImpl(SelectorProvider sp, int channels, int offset) { super(sp); this.totalChannels = channels; @@ -65,7 +68,11 @@ } void putEventOps(SelectionKeyImpl sk, int ops) { - pollWrapper.putEventOps(sk.getIndex(), ops); + synchronized (closeLock) { + if (closed) + throw new ClosedSelectorException(); + pollWrapper.putEventOps(sk.getIndex(), ops); + } } public Selector wakeup() { @@ -76,7 +83,9 @@ protected abstract int doSelect(long timeout) throws IOException; protected void implClose() throws IOException { - if (!closed) { + synchronized (closeLock) { + if (closed) + return; closed = true; // Deregister channels for(int i=channelOffset; i