谁能解释一下 和 之间的区别ProcessBuilder
,FileHandler
在什么情况下应该使用哪个。
例如,如果我们想将命令的输出重定向到一个文本文件,比如“ logfile.txt ”,ProcessBuilder
需要几秒钟才能将输出输出到该文件。
FileHandler
在 100 个进程必须将其输出发送到相同的“ logfile.txt ”的情况下,这可以做什么?
有没有办法在不使用方法的情况下将所有一百条记录输出到相同的“ logfile.txt ” ?这是我的代码,但是如果同时安排了 100 条记录,那么 p.waitfor() 方法将无济于事,因为执行命令并将每个进程的输出输出到日志文件需要几秒钟,而对于 100 个进程,这意味着需要更多是时候对数据库中的所有记录执行相同的命令了。但我的应用程序将每分钟启动一次。这就是问题所在, process.waitFor() 帮助我获得准确的输出,但更多的记录意味着需要更多的时间。我想要另一种方法,它不应该等待,但所有输出都应该同步附加到文件中。process.waitFor()
ProcessBuilder
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();
}
}
}