Can any one please explain difference between ProcessBuilder
and FileHandler
, which one should be used in which situation.
For example if we want to redirect the output of a command to a text file say "logfile.txt", ProcessBuilder
takes few seconds to get the output to the file.
What can this FileHandler
do in situations like 100 processes has to send their output to same "logfile.txt"?
Is there a way to get output of all the hundred records to same "logfile.txt" without using process.waitFor()
method in ProcessBuilder
? This is my code, but if 100 records are scheduled at same time then p.waitfor() method will not help me because it takes few seconds to execute command and get output to logfile for every process and for 100 processes means it will take more time to execute same commands for all the records in DB. but my application will start for every minute. Thats the problem, process.waitFor() helps me in getting exact output but for more number of records means it takes more time. I want another method where it shouldn't wait but all outputs should append synchronously into file.
while(rs1.next())
{
instance_id = rs1.getString(1);
startdate = rs1.getString(2);
starttime = rs1.getString(3);
endtime = rs1.getString(4);
enddate = rs1.getString(5);
if(presentdate.equals(startdate) || presentdate.equals(enddate))
{
if(presenttime.equals(starttime))
{
String[] s1 = new String[]{"cmd", "/c","ec2-start-instances",instance_id,">>","D:\\logfile.log"};
ProcessBuilder builder1 = new ProcessBuilder(s1);
Process p1 = builder1.start();
p1.waitFor();
}
else if(presenttime.equals(endtime))
{
String[] s1 = new String[]{"cmd", "/c","ec2-stop-instances",instance_id,">>","D:\\logfile.log"};
ProcessBuilder builder1 = new ProcessBuilder(s1);
Process p1 = builder1.start();
p1.waitFor();
}
}
}