- Timestamp:
- 2017-05-08T18:32:28+12:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/util/SafeProcess.java
r31651 r31664 54 54 private String inputStr = null; 55 55 private Process process = null; 56 56 private boolean forciblyTerminateProcess = false; 57 57 58 58 // output from running SafeProcess.runProcess() … … 135 135 136 136 // http://stackoverflow.com/questions/5283444/convert-array-of-strings-into-a-string-in-java 137 138 139 140 141 142 143 144 137 //log("SafeProcess running:" + Arrays.toString(command_args)); 138 StringBuffer cmdDisplay = new StringBuffer(); 139 for(int i = 0; i < command_args.length; i++) { 140 cmdDisplay.append(" ").append(command_args[i]); 141 } 142 log("SafeProcess running: [" + cmdDisplay + "]"); 143 cmdDisplay = null; // let the GC have it 144 145 145 146 146 if(this.envp == null) { … … 157 157 } 158 158 } 159 } 159 } 160 160 161 161 return prcs; … … 167 167 SafeProcess.InputStreamGobbler errorGobbler) 168 168 throws IOException, InterruptedException 169 { 169 { 170 170 // kick off the stream gobblers 171 171 inputGobbler.start(); … … 203 203 errorGobbler.interrupt(); 204 204 outputGobbler.interrupt(); 205 206 207 208 209 205 206 // Since we have been cancelled (InterruptedException), or on any Exception, we need 207 // to forcibly terminate process eventually after the finally code first waits for each worker thread 208 // to die off. Don't set process=null until after we've forcibly terminated it if needs be. 209 this.forciblyTerminateProcess = true; 210 210 211 211 // even after the interrupts, we want to proceed to calling join() on all the worker threads … … 252 252 // Run a very basic process: with no reading from or writing to the Process' iostreams, 253 253 // this just execs the process and waits for it to return. 254 255 256 257 258 254 // Don't call this method but the zero-argument runProcess() instead if your process will 255 // output stuff to its stderr and stdout streams but you don't need to monitory these. 256 // Because, as per a comment in GLI's GS3ServerThread.java, 257 // in Java 6, it wil block if you don't handle a process' streams when the process is 258 // outputting something. (Java 7+ won't block if you don't bother to handle the output streams) 259 259 public int runBasicProcess() { 260 260 try { 261 261 this.forciblyTerminateProcess = true; 262 262 263 263 // 1. create the process … … 266 266 this.exitValue = process.waitFor(); 267 267 268 268 this.forciblyTerminateProcess = false; 269 269 } catch(IOException ioe) { 270 270 … … 275 275 } 276 276 } catch(InterruptedException ie) { 277 277 278 278 if(exceptionHandler != null) { 279 279 exceptionHandler.gotException(ie); … … 288 288 destroyProcess(process); // see runProcess() below 289 289 } 290 291 290 process = null; 291 this.forciblyTerminateProcess = false; // reset 292 292 } 293 293 return this.exitValue; … … 311 311 312 312 try { 313 313 this.forciblyTerminateProcess = false; 314 314 315 315 // 1. get the Process object … … 351 351 352 352 } catch(IOException ioe) { 353 353 this.forciblyTerminateProcess = true; 354 354 355 355 if(exceptionHandler != null) { … … 381 381 } 382 382 process = null; 383 383 this.forciblyTerminateProcess = false; // reset 384 384 } 385 385 … … 394 394 395 395 try { 396 396 this.forciblyTerminateProcess = false; 397 397 398 398 // 1. get the Process object … … 428 428 429 429 } catch(IOException ioe) { 430 430 this.forciblyTerminateProcess = true; 431 431 432 432 if(exceptionHandler != null) { … … 468 468 log("*** Have called process.destroy 1"); 469 469 } 470 471 470 process = null; 471 this.forciblyTerminateProcess = false; //reset 472 472 } 473 473 … … 839 839 840 840 public InputStreamGobbler(InputStream is, boolean split_newlines) 841 { 841 { 842 842 this(); // sets thread name 843 843 this.is = is;
Note:
See TracChangeset
for help on using the changeset viewer.