求大神指教
解决方案 »
- hibernate框架下oracle和mysql怎么通用?
- 看到一段文字,震精了.....
- webservices 返回集合问题
- XFIRE实现身份验证,客户端调用WS得出list为空,急~~郁闷了两天了~~~~
- 有状态的sessionbean和无状态的sessionbean做法上有什么区别啊
- 在MyEclipse中加入spring在配置文件中bean不能别singleton属性????晕
- 使用hibernate无意间遇到很奇怪的问题
- VC6.0的SOAP调用问题
- 又是一个小问题
- 关于通过JNDI查找TopicConnectionFactory、Topic方式的问题?
- 正则表达式截取字符串
- ssh 框架整合
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();
}
}
}
}
比如中心服务器是0,下边管理了1-10个机器,这10个机器,现在有a-z总共26文件要分发,可以把a-c 分给1号,d-f 分给2号,。y-z 分给10号,然后后它们收到文件后,分别把文件发给:1-100这几台机器。这样中心服务器就没多大负载了。
如果是只有一个大文件也可以考虑,上边的这种模式。只不过是,中心服务器把程序发到它下边管理的十台或多台机器上,这几台机器只分发给某几个固定的机器。
从理论上分析,一个机器不管是单线程还是多线程总共的流量是不变的。只有把这个任务交给多台机器才是最好的。我认为这种问题没有一个最好的答案,要结合自己的业务不断的作调整。才可能找到更适合的。