ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 44544] New: pseudo-deadlock in Redirector. java caused by over-aggressive use of synchronized keyword
Date Thu, 06 Mar 2008 02:05:44 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=44544

           Summary: pseudo-deadlock in Redirector.java caused by over-
                    aggressive use of synchronized keyword
           Product: Ant
           Version: 1.7.0
          Platform: PC
        OS/Version: Windows Server 2003
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core tasks
        AssignedTo: notifications@ant.apache.org
        ReportedBy: bloch@clearwellsystems.com


I found this by using the <java> task.  The symptom is that <java> task std
output can appear hung even.

both handleOutput and handleInput methods (as well as many others) are
synchronized and handleInput can block waiting for some number of bytes to be
read.  While this happens, handleOutput and other methods will block.

So if <java> appears to be hung, keep typing at the command line and hitting
return.

I workedaround this by subclassing Java.java in a horribly hackish way as


package com.teneo.esa.ant;

import java.io.InputStream;
import java.io.IOException;
import org.apache.tools.ant.taskdefs.Java;

/**
 * @author bloch
 */
public class JavaWithWorkaround extends Java {

    private InputStream _s;

    /**
     * {@inheritDoc}
     */
    protected void setupRedirector() {
        super.setupRedirector();

        _s = redirector.getInputStream();
    }
    /**
     * {@inheritDoc}
     */
    public int handleInput(byte[] buffer, int offset, int length)
        throws IOException {
        // Should work whether or not redirector.inputStream == null:
        int n = _s.available();

        if (n == 0) {
            // Throttle
            try {
                Thread.sleep(1);
            } catch (InterruptedException ie) {
                // Ignore on purpose
            }
            return 0;
        }

        if (length > n) {
            length = n;
        }
        return super.handleInput(buffer, offset, length);
    }
}


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Mime
View raw message