gpt4 book ai didi

java - 当JVM退出时,输出流会被刷新吗?

转载 作者:行者123 更新时间:2023-12-02 05:51:01 24 4
gpt4 key购买 nike

我想知道当 JVM 在流关闭之前退出时,输出流是否会被刷新,即是否设置了 FIN 位并且另一端的 InputStream 是否可以处理数据,即使发送的数据可能会也可能不会。畸形?我的具体需求是想知道请求是否发送成功。

最佳答案

I was wondering whether the output stream will be flushed when the JVM exits

没有。

before the stream is closed

流未关闭。任何未刷新的数据都将丢失。

i.e whether the FIN bit is set

这是一个完全不同的问题。操作系统将关闭套接字,发送已刷新的所有剩余数据,并发送 FIN。

and the InputStream at the other end can process the data even though the data sent may or may not be malformed?

这取决于您的代码。 InputStream 将接收已刷新的所有数据,然后是 EOS。

My exact need is that I want to know whether the request has been sent successfully.

这是另一个完全不同的问题。如果您需要知道对等应用程序已收到数据,则它需要在应用程序协议(protocol)中向您发送确认。

基本思想是确保应用程序关闭您的流。

关于java - 当JVM退出时,输出流会被刷新吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23534699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com