【问题标题】:Java - why the system.exit(0) is not getting executed?Java - 为什么 system.exit(0) 没有被执行?
【发布时间】:2012-03-24 00:13:20
【问题描述】:

知道为什么这个 system.exit(0) 在执行 sendTCPBytes1 到 localhost 后没有被执行吗?

  public static void killerButton() throws IOException {
    String myCmd;          
    if (C.getOs().equals("Linux")) {
    } else {      
      System.out.println("[bug]: forceclose");
      sendTCPBytes1("forceclose", "localhost");   

      System.exit(0);
    }
  }


  public static void sendTCPBytes1(String filmfr2, String localhost) throws IOException {
    String downloaded = null;
    Socket socket = new Socket(localhost, 58888);
    DataOutputStream upload = new DataOutputStream(socket.getOutputStream());
    BufferedReader download = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    String c = filmfr2;
    upload.writeBytes(c);
    upload.flush();
    String get;
    downloaded = download.readLine();
    System.out.println("[TCP]: FROM server: >>> " + downloaded);
    socket.close();
}

【问题讨论】:

  • 这段代码没有意义。 C 是什么? killerButton 是从哪里调用的?
  • 你怎么知道它没有被调用?
  • 你在sendTCPBytes1中遇到异常了吗?
  • 你看到System.out.println("[TCP]: FROM server: >>> " + downloaded);的输出了吗?

标签: java windows windows-7


【解决方案1】:

假设这实际上按我认为的方式工作,readLine() 是一个阻塞调用。如果您从未收到任何输入,它将无限期地等待。

【讨论】:

    【解决方案2】:

    如果您的套接字连接失败,例如抛出 IOException,System.exit(0) 不会被调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-25
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-16
      相关资源
      最近更新 更多