Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: done

...

This noncompliant code example invokes notemaker using the exec() method, which returns an object of a subclass of the abstract class java.lang.Process. The exitValue() method returns the exit value for processes that have terminated, but it throws an IllegalThreadStateException when invoked on an active process. Because this noncompliant example program fails to wait for the notemaker process to terminate, the call to exitValue() is likely to throw an {IllegalThreadStateException}}.

Code Block
bgColor#FFcccc
public class Exec {
  public static void main(String args[]) throws IOException {
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("notemaker");
    int exitVal = proc.exitValue();
  }
}

...

This noncompliant code example properly drains empties the input stream from the process, thereby preventing the input stream buffer from becoming full and blocking. However, it ignores the error stream, which can also fill and cause the process to block.

...

This compliant solution redirects the process's error stream to its input stream. Consequently, the program can drain empty the single output stream without fear of blockage.

...

When the output and error streams are handled separately, they must be drained emptied independently. Failure to do so can cause the program to block indefinitely.

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ca76ff8fccdbf51e-272d5c78-447143f4-adbb8405-b8aff8660d37e75440eddabf"><ac:plain-text-body><![CDATA[

[[API 06

AA. Bibliography#API 06]]

method [exec()

http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html#exec(java.lang.String)]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e7e8b6636bc60e87-1b5c0cf9-41404ec1-a8778372-4a2226c3e6a9519dc63c5483"><ac:plain-text-body><![CDATA[

[[Daconta 00

AA. Bibliography#Daconta 00]]

 

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5816b471b9ddc556-b566ec7d-4a9e4918-9e8c8cd5-8246ca5a867f7889224b5527"><ac:plain-text-body><![CDATA[

[[Daconta 03

AA. Bibliography#Daconta 03]]

Pitfall 1

]]></ac:plain-text-body></ac:structured-macro>

...