My threads stop after a few hours of running
I need to run some bash commands that each of them takes about 18 hrs to
finish. In order to use all the available CPU cores I ran each command on
a separate thread using the following code. However, the threads stop
doing anything after about 5 hrs of working. I know that by checking the
cpu usage. When I run only one command using the same code it runs fine.
Also I ran several commands in different bash terminal sessions to make
sure they are really independent.
public class RunBashCommand implements Runnable{
private String[] command;
private String fSSubjectFolder;
private String subjectId;
RunBashCommand ( String[] newCommand, String newSubjectFolder, String
newSubjectId ) {
command = newCommand;
fSSubjectFolder = newSubjectFolder;
subjectId = newSubjectId;
}
public void run ( ){
runCommand ();
}
private void runCommand (){
Runtime run = Runtime.getRuntime();
Process p;
try {
String line;
p = run.exec(command);
BufferedReader buf = new BufferedReader( new
InputStreamReader(p.getInputStream() ) );
PrintWriter pw = new PrintWriter( new File(
fSSubjectFolder+"/"+subjectId+"CTPFS.log" ) );
while ( ( line = buf.readLine() ) != null ){
pw.println( line );
}
p.waitFor();
pw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and in the parent thread, that invoke this class, I have:
Runnable runBash = new RunBashCommand( command, "folderAddress1",
"folderAddress2" );
Thread runBashThread = new Thread ( runBash );
runBashThread.setName ( "some name" );
runBashThread.start();
RunCTPFS.threads.add(runBashThread); // my thread list for thread tracking
Any help would be most appreciated. I am suspicious of starvation.
No comments:
Post a Comment