Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Machine > OutOfMemoryErro...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 715 of 803
Post > Topic >>

OutOfMemoryError problem

by "mike" <mikaelpetterson@[EMAIL PROTECTED] > Sep 7, 2006 at 11:01 AM

Hi,

I am a user of cruisecontrol ( continuous integration server). As long
as I have used it I have had problems with
java.lang.OutOfMemoryError's. I have gotten numerous ideas on how to
handle it. Some
resonable and some more unrealistic. However lately I dicided that I
need to dig deeper into this.
I use two ways to perform build and test. Both ways use the same 'ant'
and the same 'build file'.
The difference is in how the build is triggered.

Shell script
=========

Here I use a shell script to start ant.
java -Xms512M -Xmx756M -classpath .......

Cruisecontrol
==========

Here I start cruisecontrol ( a java program) that starts ant.
I set Xms and Xmx for cruisecontrol as well as ant.

When I execute the shell script the 'junit' and 'junitreport' tasks
execute nicely.

On the other hand when I execute 'cruisecontrol' I get a
java.lang.OutOfMemoryError when I execute the 'junit-report'.

Trace:
--------
BUILD FAILED
 java.lang.OutOfMemoryError
         at
 org.apache.tools.ant.Project.executeSortedTargets(Project.java:1225)
         at
org.apache.tools.ant.Project.executeTarget(Project.java:1185)
         at

org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecut
 or.java:40)
         at
 org.apache.tools.ant.Project.executeTargets(Project.java:1068)
         at org.apache.tools.ant.Main.runBuild(Main.java:668)
         at org.apache.tools.ant.Main.startAnt(Main.java:187)
         at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
         at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
 Caused by: java.lang.OutOfMemoryError
 --- Nested Exception ---
 java.lang.OutOfMemoryError

I did some investigation in ant ( source code ) and found out the each
junit test suite result ( xml-file) is merged into one big xml file.

There are two steps in the code. Step 1 works ok! Step 2 is failing
siince the big merged file is not complete.  Could it be something with
the jvm?

All hints are welcome.

cheers,

//mikael

Step 1 - creating the dom document
-------------------------------------------

protected Element createDocument() {
        // create the dom tree
        DocumentBuilder builder = getDocumentBuilder();
        Document doc = builder.newDocument();
        Element rootElement = doc.createElement(TESTSUITES);
        doc.appendChild(rootElement);

        generatedId = 0;

        // get all files and add them to the document
        File[] files = getFiles();
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            try {
                log("Parsing file: '" + file + "'",
Project.MSG_VERBOSE);
                if(file.length()>0) {
                    Document testsuiteDoc
                            =
builder.parse(FileUtils.getFileUtils().toURI(files[i].getAbsolutePath()));
                    Element elem = testsuiteDoc.getDocumentElement();
                    // make sure that this is REALLY a testsuite.
                    if (TESTSUITE.equals(elem.getNodeName())) {
                        addTestSuite(rootElement, elem);
                        generatedId++;
                    } else {
                        //wrong root element name
                        // issue a warning.
                        log("the file " + file
                                + WARNING_INVALID_ROOT_ELEMENT,
                                Project.MSG_WARN);
                    }
                } else {
                    log("the file " + file
                            + WARNING_EMPTY_FILE,
                            Project.MSG_WARN);
                }
            } catch (SAXException e) {
                // a testcase might have failed and write a zero-length
document,
                // It has already failed, but hey.... mm. just put a
warning
                log("The file " + file + WARNING_IS_POSSIBLY_CORRUPTED,
Project.MSG_WARN);
                log(StringUtils.getStackTrace(e), Project.MSG_DEBUG);
            } catch (IOException e) {
                log("Error while accessing file " + file + ": "
                    + e.getMessage(), Project.MSG_ERR);
            }
        }
        return rootElement;
    }


Step 2 - write the DOM Tree to file
----------------------------------------

protected void writeDOMTree(Document doc, File file) throws IOException
{
        OutputStream out = null;
        PrintWriter wri = null;
        try {
            out = new BufferedOutputStream(new FileOutputStream(file));
            wri = new PrintWriter(new OutputStreamWriter(out, "UTF8"));
            wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
            (new DOMElementWriter()).write(doc.getDocumentElement(),
wri, 0, "  ");
            wri.flush();
            // writers do not throw exceptions, so check for them.
            if (wri.checkError()) {
                throw new IOException("Error while writing DOM
content");
            }
        } finally {
            FileUtils.close(wri);
            FileUtils.close(out);
        }
    }




 1 Posts in Topic:
OutOfMemoryError problem
"mike" <mika  2006-09-07 11:01:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon May 12 2:16:17 CDT 2008.