Author: markt Date: Mon Jan 14 13:49:09 2013 New Revision: 1432917 URL: http://svn.apache.org/viewvc?rev=1432917&view=rev Log: Expand the scope of the lock to prevent concurrent blocking and non-blocking writes
Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java?rev=1432917&r1=1432916&r2=1432917&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java Mon Jan 14 13:49:09 2013 @@ -29,7 +29,7 @@ public abstract class AbstractServletOut StringManager.getManager(Constants.Package); private final Object fireListenerLock = new Object(); - private final Object nioWriteLock = new Object(); + private final Object writeLock = new Object(); // Start in blocking-mode private volatile WriteListener listener = null; @@ -91,17 +91,17 @@ public abstract class AbstractServletOut private void writeInternal(byte[] b, int off, int len) throws IOException { - if (listener == null) { - // Simple case - blocking IO - doWrite(true, b, off, len); - } else { - // Non-blocking IO - // If the non-blocking read does not complete, doWrite() will add - // the socket back into the poller. The poller way trigger a new - // write event before this method has finished updating buffer. This - // sync makes sure that buffer is updated before the next write - // executes. - synchronized (nioWriteLock) { + synchronized (writeLock) { + if (listener == null) { + // Simple case - blocking IO + doWrite(true, b, off, len); + } else { + // Non-blocking IO + // If the non-blocking read does not complete, doWrite() will add + // the socket back into the poller. The poller way trigger a new + // write event before this method has finished updating buffer. This + // sync makes sure that buffer is updated before the next write + // executes. int written = doWrite(false, b, off, len); if (written < len) { // TODO: - Reuse the buffer --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org