Background:
You need to add a button to the project's Test tool to open an EXE tool directly after you click it.
The function of this tool is to import TXT file into Excel report output.
But after parsing two lines will stop moving, also do not error. After you close the test tool, it runs smoothly.
Reason:
TXT to Excel report process, the intermediate information is in memory, the buffer space is occupied, the program is blocked, has been waiting for the release of buffer space resources, so need to establish a thread in time to empty the buffer.
Workaround:
1. Creating the Streamclean thread class
/* * Create threads to clear the blocking area in a timely manner to avoid blocking child threads (problems that occur when calling external tools Txt->excel. ) */public class Streamclean extends Thread { InputStream is; String type; Public Streamclean (InputStream are, String type) { this.is = is; This.type = type; } public void Run () { try { InputStreamReader ISR = new InputStreamReader (is); BufferedReader br = new BufferedReader (ISR); String line = null; while (line = Br.readline ())! = null) { System.out.println (type + ">" + line);//console Output } } catch (Ioexce Ption IoE) { ioe.printstacktrace (); }
2. Add the following code at the call exe execution file
Process process = NULL; try { process =runtime.getruntime (). exec (Txttoexcel);//txttoexcel is the DOS command that invokes the tool new Streamclean ( Process.getinputstream (), "INFO"). Start (); New Streamclean (Process.geterrorstream (), "ERROR"). Start (); Process.waitfor (); } catch (Throwable t) {t.getstacktrace (); } finally {if (process! = null) { Process.destroy ();} process = Null;
}
There's a problem with the wood.
Executable jar package calls EXE executable file, child process blocked