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] pseudo-deadlock in Redirector. java caused by over-aggressive use of synchronized keyword
Date Thu, 06 Mar 2008 11:04:57 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=44544





--- Comment #2 from Eric Bloch <bloch@clearwellsystems.com>  2008-03-06 03:04:56 PST
---
Here ya go!

--

<project name="bug-xxxxx" default="bug" >
    <target name="bug">
        <java classname="ReaderAndWriter" >
            <classpath>
                <pathelement path="${basedir}"/>
            </classpath>
        </java>
    </target>
</project>

and src code for ReaderAndWriter below

--
import java.io.*;

class Reader extends Thread {
    public void run() {
        try {
            while(true) {
                int x = System.in.read();
                if (x == -1) {
                    break;
                }
            }
        } catch (IOException ioe) {
            return;
        }
    }
}

public class ReaderAndWriter {
    static public void main(String[] args) {
        Reader reader = new Reader();
        reader.start();

        for(int i = 1; i < 10; i++) {
            System.out.println("I love ant.");
        }
    }
}

--


Run ant and notice the hangs.  Everytime you hit carriage return
you can see some output go by.  Expected results is you'd see your 10 lines of
output get printed and then ant should exit.  As I read the code in Redirector,
it needs some love wrt the aggressive use of synchronization.  There's no need,
afa I can tell for writes to be locked out while you're reading.




I fixed by workaround to be more striaghtfwd too.  Here it is now:

/*
 * CONFIDENTIAL COMPUTER CODE AND INFORMATION
 * COPYRIGHT (C) 2004-2008 TENEO SYSTEMS, INC. ALL RIGHTS RESERVED.
 * REPRODUCTION BY ANY MEANS EXPRESSLY FORBIDDEN WITHOUT THE WRITTEN
 * PERMISSION OF THE OWNER.
 */
package com.teneo.esa.ant;

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

/**
 * Workaround for Ant bug: 44544; 
 * See https://issues.apache.org/bugzilla/show_bug.cgi?id=44544
 *
 * @author bloch
 */
public class JavaWithWorkaround extends Java {

    private InputStream _s;

    /**
     * {@inheritDoc}
     */
    @Override protected void setupRedirector() {
    }

    /**
     * {@inheritDoc}
     */
    @Override protected void handleOutput(String output) {
        log(output, Project.MSG_INFO);
    }

    /**
     * {@inheritDoc}
     */
    @Override protected void handleFlush(String output) {
        handleOutput(output);
    }

    /**
     * {@inheritDoc}
     */
    @Override public int handleInput(byte[] buffer, int offset, int length)
        throws IOException {
        return getProject().defaultInput(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