线程写好了,从判断到调用shell文件但是问题又来了,很奇怪there is 13 files, then load......../db2home/db2inst1/ap/ap_load_sx.sh read line:proess is running! check dir_ap:/db2home/db2inst1/ap/ap_file_he/ there is 13 files, then load......../db2home/db2inst1/ap/ap_load_he.sh read line:proess is running!这里判断是说,2个shell文件都在跑着,但实际上没有跑 这是单独运行ap_load_sx.sh和ap_load_he.sh 都可以偏偏我的线程调用shell时,shell自己打印proess is running!奇怪!
线程写好了,从判断到调用shell文件但是问题又来了,很奇怪there is 13 files, then load......../db2home/db2inst1/ap/ap_load_sx.sh read line:proess is running! check dir_ap:/db2home/db2inst1/ap/ap_file_he/ there is 13 files, then load......../db2home/db2inst1/ap/ap_load_he.sh read line:proess is running!这里判断是说,2个shell文件都在跑着,但实际上没有跑 这是单独运行ap_load_sx.sh和ap_load_he.sh 都可以偏偏我的线程调用shell时,shell自己打印proess is running!奇怪!
发现问题所在了,但是不知道怎么解决 Process pro = Runtime.getRuntime().exec("ap_load_he.sh"); 这样是可以的 Process pro = Runtime.getRuntime().exec("/db2home/db2inst1/ap/ap_load_he.sh"); 这样就不行,报proess is running!
“proess is running ” 是shell程序打印的,我读了出来
估计是shell只支持当前目录执行String cmd[] = {"sh","/bin/bash","cd /db2home/db2inst1/ap/;pwd; ap_load_he.sh"}; Process pro = Runtime.getRuntime().exec(cmd); 这样好像也不行
import java.util.Calendar;public class ConquerFinder extends Thread {
// 文件夹路径
private String folderPath = null;
// 达到多少文件
private int limitCount = 0;
// 是否正在执行
private boolean isExecute = false;
public ConquerFinder(String folderPath, int limitCount) {
this.folderPath = folderPath;
this.limitCount = limitCount;
}
public void run() {
while(true) {
// 得到当前时
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
if (hour > 0 && hour < 8) {
isExecute = false;
continue;
}
if (isExecute) {
continue;
}
File folder = new File(folderPath);
// 如果不是文件夹路径,推出
if (!folder.isDirectory()) {
System.err.print("File path is not a directory");
System.exit(0);
}
// 得到文件夹下子文件的数量
File[] sonFile = folder.listFiles();
if (sonFile.length > limitCount) {
// 如果大于所要数量,此处执行.sh
// 设置执行flag
isExecute = true;
}
} }
}
我这里只能提供你一个思路,这个线程可以看成是一个死循环,并且在判断时间的时候可以设置如果没有在这个时间范围内,sleep一段时间,看你需求了。
read line:proess is running!
check dir_ap:/db2home/db2inst1/ap/ap_file_he/
there is 13 files, then load......../db2home/db2inst1/ap/ap_load_he.sh
read line:proess is running!这里判断是说,2个shell文件都在跑着,但实际上没有跑
这是单独运行ap_load_sx.sh和ap_load_he.sh 都可以偏偏我的线程调用shell时,shell自己打印proess is running!奇怪!
read line:proess is running!
check dir_ap:/db2home/db2inst1/ap/ap_file_he/
there is 13 files, then load......../db2home/db2inst1/ap/ap_load_he.sh
read line:proess is running!这里判断是说,2个shell文件都在跑着,但实际上没有跑
这是单独运行ap_load_sx.sh和ap_load_he.sh 都可以偏偏我的线程调用shell时,shell自己打印proess is running!奇怪!
Process pro = Runtime.getRuntime().exec("ap_load_he.sh"); 这样是可以的
Process pro = Runtime.getRuntime().exec("/db2home/db2inst1/ap/ap_load_he.sh");
这样就不行,报proess is running!
Process pro = Runtime.getRuntime().exec(cmd); 这样好像也不行