当前位置:编程学习 > JAVA >>

多线程调用VC

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<String> id, time, zhan; 
        private boolean flag; 
        private Data data; 
        int xx = 0; 
 
        public GenerateData(List<String> id, List<String> time, 
                List<String> zhan, Data data) { 
            this.id = id; 
        

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,