通过java程序进行rsync-远程连接失败的问题

发布于 2024-12-20 17:55:42 字数 781 浏览 6 评论 0原文

我正在通过我的 java 应用程序运行 rsync。(Solaris Evn)

Java 应用程序将与远程计算机同步文件。在我们的连接失败测试期间,我们注意到通过 java 程序运行 rsync 的问题。如果同步过程中出现任何连接问题,在源端运行的 java 应用程序不会收到任何错误消息。

有关测试场景的简要详细信息:

  1. 我们运行 Java 程序
  2. java 程序启动 rsync 命令并将大量文件从源同步到远程目标
  3. 在同步过程中,我们运行 ps - EF | grep rsync 检查进程是否在(源和目标)端运行。双方 rsync 进程都在运行。
  4. 我们识别目标机器上的 rsync 进程 ID,并使用 kill -9 终止该进程。java
  5. 代码没有收到任何错误消息,也没有退出。它只是挂了。
  6. 还注意到 rsync 进程仍在源端运行,并且 rsync 进程也没有在日志文件中打印任何日志消息。

    注意:如果我们直接运行 rsync 命令(而不是通过 java 程序),那么一切正常。当我们在目标处停止 rsync 进程时,源进程将停止。

    当 RSYNC 在目标处终止时,Java 程序和 RSYNC 未检测到目标有问题。没有写入日志文件,Java 程序将挂起并变得无响应。

    通过perl它工作正常。不知道java有什么问题......!!!

    我没有任何线索来调试这个问题。 请分享您的想法和调试指针。

I am running rsync through my java application.(Solaris Evn)

The Java application will sync the files with remote machine. During our connection failure testing we noticed an issue running rsync through java program. The java application which is running at source side is not receiving any error message if there are any connection issues during the sync process.

Brief details about the test scenario:

  1. We run the Java Program
  2. The java program starts the rsync command and sync the large number of files from source to remote destination
  3. During the sync process we run the ps -ef | grep rsync to check whether the processes are running or not at both(source and dest) side. Both side rsync processes are running.
  4. We identify the rsync process id at target machine and kill the process with kill -9 <pid>
  5. The java code didn't receive any error message and didn't exit. It just hung.
  6. And also noticed that the rsync process is still running at source side and rsync process is also not printing any log message in the log file.

    Note : If we run the rsync command directly (not through java program) , then everything is working fine. When we stop the rsync process at target the source process will be stopped.

    When RSYNC terminated at target, the Java program and RSYNC is not detecting that the target has issues. No log files written , Java program will hang and becomes unresponsive.

    Through perl its working fine. Not sure what the problem with java...!!!

    I don’t have any clues to debug this issue.
    Please share your thoughts and pointer to debug.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一萌ing 2024-12-27 17:55:42

在 Java 端,我建议创建两个额外的线程来使用 Process p 的 p.getInputStream() 和 p.getErrorStream() 流。我认为这有助于 rsync 感受到更多的爱和关心。

像这样的事情(为了简单起见,我忽略了 IOExceptions --- 你必须处理它们!):

final Process p = Runtime.exec("rsync"); // however you do this...

Runnable consumeIn = new Runnable() {
  public void run() {
    InputStream in = p.getInputStream();
    InputStreamReader isr = new InputStreamReader(in, "UTF-8");
    BufferedReader br = new BufferedReader(isr);
    String line;
    while ( (line = br.readLine()) != null ) {
      // Throw away the data?  Or do something with it if you like!
    }
  }
};

Runnable consumeErr = new Runnable() {
  public void run() {
    InputStream in = p.getErrorStream();
    // etc... (very similar to consumeIn)
  }
};

new Thread(consumeIn).start();
new Thread(consumeErr).start();

In your Java side I recommend creating two additional threads to consume the p.getInputStream() and p.getErrorStream() streams of your Process p. I think that helps rsync feel more loved and cared for.

Something like this (I'm ignoring IOExceptions for simplicity --- you'll have to deal with them!):

final Process p = Runtime.exec("rsync"); // however you do this...

Runnable consumeIn = new Runnable() {
  public void run() {
    InputStream in = p.getInputStream();
    InputStreamReader isr = new InputStreamReader(in, "UTF-8");
    BufferedReader br = new BufferedReader(isr);
    String line;
    while ( (line = br.readLine()) != null ) {
      // Throw away the data?  Or do something with it if you like!
    }
  }
};

Runnable consumeErr = new Runnable() {
  public void run() {
    InputStream in = p.getErrorStream();
    // etc... (very similar to consumeIn)
  }
};

new Thread(consumeIn).start();
new Thread(consumeErr).start();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文