日期:2014-05-17 浏览次数:20680 次
import java.io.File; import java.io.IOException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class test { /** * @param args * @throws IOException */ private final static String TEMPDIR = "/home3/boweiy/hadoopdir/temp/"; public static void main(String[] args) throws IOException { // TODO Auto-generated method stub FileToNameNodeForExp(); } public static boolean FileToNameNodeForExp() { boolean done = false; String[] fNames = new File(TEMPDIR).list(); int fn = fNames.length; System.out.println(fn); for(int i = 0; i < fn; i++) { System.out.println(fNames[i]); Thread t = new Thread(new UpThread("node2", TEMPDIR + fNames[i])); t.start(); if(Thread.currentThread().isInterrupted()) System.out.println("Something wrong:" + fNames[i]); } return done; } } class UpThread implements Runnable { private String namenode; private String filename; public UpThread(String namenode, String filename) { this.namenode = namenode; this.filename = filename; } public void run() { // TODO Auto-generated method stub String com = "scp " + filename + " boweiy@" + namenode + ":/home/boweiy/temp/"; String[] coms = new String[3]; coms[0] = "scp"; coms[1] = filename; coms[2] = "boweiy@" + namenode+ ":/home/boweiy/temp/"; Process process; try { process = Runtime.getRuntime().exec(coms); process.waitFor(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }