多线程调用VC(一)

2014-11-24 02:47:44 · 作者: · 浏览: 0

Java代码
package sai;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Data {

private static final String path = Thread.currentThread()
.getContextClassLoader().getResource("").getPath();
boolean flag=false;
Process proc;
public synchronized void GenerateFile(String infile, String outfile) {

String inpath = path.substring(1, path.indexOf("bin"))
+ "AdvancedARMA/Release/";
String outpath = path.substring(1, path.indexOf("bin")) + "T/";
String outpath2 = path.substring(1, path.indexOf("bin")) + "Txt2/";
File file = new File(outpath2+outfile);

if (file.exists()) {
try {
wait();
} catch (InterruptedException e) {
}
}
notify();// 唤醒阻塞队列的某线程到就绪队列
String exeFileName = inpath + "AdvancedARMA.exe";
String para = outpath + infile + " " + outpath2 + outfile + " 10";

String cmd = exeFileName + " " + para;

try {
proc = Runtime.getRuntime().exec(cmd);

} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Error exec!");
}

finally{
if(proc==null){
proc.destroy();

}


}


}

private synchronized String getData(String filepath) {

String inpath = path.substring(1, path.indexOf("bin")) + "Txt2/";
String lastline = "";

String fname = inpath + filepath;
File file = new File(fname);
if (!file.exists()) {
try {
wait();
} catch (InterruptedException e) {
}
}

notify();// 唤醒阻塞队列的某线程到就绪队列

try {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(fname)));
String line;

while ((line = br.readLine()) != null) {
lastline = line;

}
br.close();
//file.delete();//删除临时文件
} catch (FileNotFoundException e) {

System.out.println("文件正在创建中...");
} catch (IOException e) {
e.printStackTrace();
}
return lastline;
}


static class GenerateData extends Thread {

private List id, time, zhan;
private boolean flag;
private Data data;
int xx = 0;

public GenerateData(List id, List time,
List zhan, Data data) {
this.id = id;
this.time = time;
this.zhan = zhan;
this.data = data;
}

public void run() {

for (int s = 0; s < id.size(); s++) {
for (int z = 0; z < time.size(); z++) {
for (int y = 0; y < zhan.size(); y++) {
for (int i = 0; i < zhan.size(); i++) {

if (y == i) {continue;}