Note that there are some explanatory texts on larger screens.

plurals
  1. POWebapp that runs process won't complete
    text
    copied!<p>So I've got a couple of shell scripts that run on a server. They do some time intensive data gathering and then complete. They seem to work fine when I run them from the server. I'm now trying to automate these with a Spring webapp. Everything is running and I can run the scripts through ProcessBuilder, but for some reason, when the scripts are run through ProcessBuilder they only get about halfway and then just stop responding.</p> <p>I'm really hoping someone will have some thoughts on why this might be. Unfortunately due to the work I can't really post much in the way of code. I can post the webapp code that runs the processes, which I'll do down below, but I can't post the scripts. If anyone has some thoughts please chime in. Thanks.</p> <pre><code>@Entity public class Job implements Runnable { @Id @GeneratedValue private Long id; //getters and setters @Override public void run() { Process p = null; try { BufferedWriter bw = new BufferedWriter(new FileWriter("/opt/condor/bin/datafile")); bw.write(this.getName()); bw.close(); p = new ProcessBuilder("/opt/condor/bin/scripts/create-filter.sh").start(); jobHelper(p); List&lt;String&gt; dates = datesBetween(); status = "Running Master"; for(String temp : dates) { String[] splitDate = temp.split("-"); String tmpYear = splitDate[0]; String tmpMonth = splitDate[1]; String tmpDay = splitDate[2]; log.info("Running Master script: master.sh " + this.getCustomer() + ", " + this.getProject() + ", " + tmpYear + ", " + tmpMonth + ", " + tmpDay); p = new ProcessBuilder("/opt/condor/bin/scripts/master.sh", this.getCustomer(), this.getProject(), tmpYear, tmpMonth, tmpDay).start(); log.info("Entering job helper"); jobHelper(p); log.info("exited job helper"); } status = "Finished Master"; log.info("Finished Master"); } catch (IOException ioe) { log.error("IO Error: " , ioe); ioe.printStackTrace(); } log.info("Done running script"); endTime = Long.toString(System.currentTimeMillis()); status = "Ended"; JobManager.FinishJob(this); } private boolean jobHelper(Process p) { log.info("inside job helper"); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; try { while ((line = br.readLine()) != null) { log.info(line); if(line.contains("Uh oh!")) return true; } boolean running = true; while(running) { log.info("waiting..."); p.waitFor(); log.info("done waiting"); running = false; } } catch (IOException e) { log.error("IO Error: " , e); e.printStackTrace(); } catch (InterruptedException e) { log.error("Interrupted Exception: ", e); e.printStackTrace(); p.destroy(); } return false; } } </code></pre> <p>I apologize for any syntactical errors you see, the code does compile and run so please just ignore them. I was copying and pasting the relevant bits of code and may have messed up something in that regard.</p> <p><strong>EDIT</strong></p> <p>I added some log statements in different places and can see that the code is entering my helper, which is why it is displaying output, but at some point it just stops. it doesn't ever seem to hit the log statements surrounding the p.waitFor() method. Clearly I'm not doing something right, which is understandable since threads are a huge weakpoint of mine. I'm guessing maybe it is getting hung up displaying stuff and I'm then getting a deadlock situation but I really don't understand where or how to fix it. Can anyone let me know what I'm screwing up and what I need to do to fix it? I could really use an example as well, thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload