求大神指教

解决方案 »

  1.   

    delivery 一个文件,同时发送到若干台服务器上
      

  2.   

    还是给你写了段代码,你参考一下吧:package com.test;import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;public class Test {

    public static byte[] context = new byte[0];

    public static void main(String[] args) {
    File file = new File("E:/IPOP V3.6帮助文档.doc");
    readFile(file);
    String fileName = file.getName();

    WriterClient client1 = new WriterClient("E:/client/1/", fileName);
    WriterClient client2 = new WriterClient("E:/client/2/", fileName);

    client1.start();
    client2.start();
    }

    public static void readFile(File file) {
    InputStream in = null;
    try {
    in = new FileInputStream(file);
    int i = 0;
    byte[] buf = new byte[1024 * 4];
    while((i=in.read(buf)) != -1){
    byte[] newCxt = new byte[context.length + i];
    System.arraycopy(context, 0, newCxt, 0, context.length);
    System.arraycopy(buf, 0, newCxt, context.length, i);
    context = newCxt;
    }
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally{
    try {
    in.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    }class WriterClient extends Thread{

    private String address;
    private String fileName;

    public WriterClient(String address, String fileName){
    this.address = address;
    this.fileName = fileName;
    }

    @Override
    public void run(){
    File file = new File(address, fileName);

    OutputStream out = null;
    try {
    out = new FileOutputStream(file);
    out.write(Test.context);
    out.flush();
    } catch (IOException e) {
    e.printStackTrace();
    } finally{
    try {
    out.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    }
      

  3.   

    你怎么分发? 不还是要分发到 目标服务器的  ftp 或sftp 或者硬盘目录被队列调用 被 有什么疑惑? 
      

  4.   

    如果这样的话就不好处理了。如果传的文件比较多的话可以这样实现:找一个中心服务器,管理十台或多台机器,这十几台机器上都有一个文件分发的程序,如果某个机器收到一个文件,它就会把这个文件分发到其它机器上,中心服务器分别管理这几台机器的文件分配工作。这样中心服务器负载不就小多了。
    比如中心服务器是0,下边管理了1-10个机器,这10个机器,现在有a-z总共26文件要分发,可以把a-c 分给1号,d-f 分给2号,。y-z 分给10号,然后后它们收到文件后,分别把文件发给:1-100这几台机器。这样中心服务器就没多大负载了。
    如果是只有一个大文件也可以考虑,上边的这种模式。只不过是,中心服务器把程序发到它下边管理的十台或多台机器上,这几台机器只分发给某几个固定的机器。
    从理论上分析,一个机器不管是单线程还是多线程总共的流量是不变的。只有把这个任务交给多台机器才是最好的。我认为这种问题没有一个最好的答案,要结合自己的业务不断的作调整。才可能找到更适合的。