我正在使用 java 命令执行批处理文件并读取放入数据库的文本文件中的批处理数据。例如,我必须使用相同的批处理文件在 15 分钟间隔内运行 430 个节点。所以我将 430 个节点划分为 12 个线程,所以每个线程包含 40 个指向同一个批处理文件的节点。但是并行运行的线程不能等待批处理文件命令完成。我不能等待每个线程,因为所有任务都应该在 15 分钟内完成。有什么建议么?
下面是运行多线程的一段代码。
for (int i = 0; i < noOfMainThreads; i++) {
// running 12 thread for 40 node
threadArr[i] = new Thread(runnableArr[i]);
runnableArr[i] = new CodeBatchfile(nodeArr,nodeidArr);
}
for (int i = 0; i < noOfMainThreads; i++) {
threadArr[i].start;
}
class CodeBatchfile{
void run(){
for (int i=1;i<nodename.length;i++) {
// exciting batch file using 12 threads.
cmd = filepath + " " + nodenamelocal;
try {
process = Runtime.getRuntime().exec(cmd, null, bdir);
process.waitFor();
}
catch(Exception ex) {
System.out.println("Exception Running batch file" + ex.getLocalizedMessage());
}
}
}