By making use of the SwingWorker class the GUI is updated in the Worker Thread .This makes it
possible for the data to be available in the GUI concurrently when read from the inputStream.

Here the doInBackground process runs the Complex Process and when we publish a data via publish method,the result can be made to be appended to the GUI by the process method.The code in the process methos is executed in the worker Thread so make sure to put the GUI updating code here.

The done method is executed once the process is completed.

Above code is liable to hanging as the process's getErrorStream and getOutputStream is executed in the same thread.So make sure you make the getErrorStream and getOutputStream to be executed in a separate Thread.

The correct solution according to my experience is the getErrorStream and getOutputStream
of the Process must be executed concurrently in a separate Thread

When you run a Process proc

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);

You need to empty errorStream and outputStream in a separate Thread concurrently.
In case if you get the outputStream first and get ErrorStream afterwards it may lead to the Process hang or vice versa.

To make the empty the errorStream and outputStream in a separate Thread you can use StreamGobbler as follows: