多线程

package com.jyc.filter;

import java.io.File;
import java.io.FileFilter;

import com.jyc.runnable.Runner1;

public class Test implements FileFilter{

@Override
public boolean accept(File pathname) {
String filename = pathname.getName().toLowerCase();
//System.out.println("-- "+pathname.getName());
if(filename.endsWith(".ctl")){
return true;
}else{
return false;
}
}
/*
* C:\sqlldr\a.ctl
C:\sqlldr\b.ctl
C:\sqlldr\c.ctl
C:\sqlldr\d.ctl
C:\sqlldr\e.ctl
C:\sqlldr\f.ctl
C:\sqlldr\g.ctl
C:\sqlldr\h.ctl
*/
public static void main(String[] args) {
File file = new File("C:\\sqlldr");
File[] files = file.listFiles(new Test());
for(File f : files){
System.out.println(f.getPath());
//new Thread(new Runner1(f.getPath())).start();
}
}
}

 

package com.jyc.runnable;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Runner1 implements Runnable {

private String str;

public Runner1(String str) {
this.str = str;
}
@Override
public void run() {

//System.out.println(" = "+str); d.ctl
String cmd = "d:/db/oracle/product/10.2.0/db_2/bin/sqlldr userid=jyc/jyc@orcl control=" +
//"C:/mycontrl.ctl"
str
+" bad=c:/bad.txt";
try {
Process ldr = Runtime.getRuntime().exec(cmd);
InputStream stderr = ldr.getInputStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null)
System.out.println("*** " + line);
stderr.close();
isr.close();
br.close();
try {
ldr.waitFor();
} catch (Exception e) {
System.out.println("process function:loader wait for != 0");
}
} catch (Exception ex) {
System.out.println("process function:loader execute exception"
+ ex.toString());
}

}

}

posted @ 2016-12-25 17:18  My_blog_s  阅读(144)  评论(0编辑  收藏  举报