我有 2 台机器(Intel Atom(TM) CPU D525),每台都运行不同的操作系统(1 个 windows 7 和 1 个 ubuntu 10.04)。
我希望将一堆图像从 Windows 7 机器发送到 Ubuntu 机器。
我现在正在使用多线程来做到这一点。我在下面附上了我的代码:
public class RshScp implements Runnable
{
private StreamHandlers streamHandlers = new StreamHandlers();
private String screenFileName;
private int clientIndex;
private SingletonServer ss = null;
public RshScp(String screenFileName, int clientIndex, SingletonServer ss)
{
this.screenFileName = screenFileName;
this.clientIndex = clientIndex;
this.ss = ss;
}
public void run()
{
sendFileToClient();
}
public void sendFileToClient()
{
try
{
DisplayClient dc = null;
dc = ss.getClient(clientIndex);
String execution = sshFileRSH(dc.getHostName(), dc.getUserName(), screenFileName, dc.getRemoteDirectory(), dc.getLocalDirectory());
log.write(execution);
Process p1 = Runtime.getRuntime().exec(execution);
InputStreamReader isr = new InputStreamReader(p1.getInputStream());
streamHandlers.checkStreamOutput("From RshScp", isr);
} catch(Exception e){}
}
//Function to set the RSH SCP command
private String sshFileRSH(String hostName, String userName, String localFileNames, String remoteDirName, String localJobDirectory)
{
String fileTransferCommand = "scp " + localFileNames;
//String fileTransferCommand = "rsync --partial --progress --rsh=ssh " + localFileNames[0] + " " + localFileNames[1] + " " + localFileNames[2];
String destinationCommand = userName + "@" + hostName + ":" + remoteDirName;
String executionCommand = "";
executionCommand = fileTransferCommand + " " + destinationCommand;
return executionCommand;
} // end function
}//end while class
当我尝试将文件发送到多个客户端时,我发现它很慢。它使用 5 秒连接并将文件发送到客户端。有时它仍然会丢失图像。
有谁知道导致多线程变慢的实际情况?是否有任何解决方案可以使其连接和发送更快?