程序在bufferedreader关闭时冻结 [英] Program freezes on bufferedreader close

查看:101
本文介绍了程序在bufferedreader关闭时冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关闭缓冲的读取器时程序冻结。使用适用于Minecraft的Forge Modding API,但是在使用独立服务器端代码之前,我曾遇到过此问题。这个特定的代码运行良好,然后随机开始给我这个问题,不确定如何解决此问题。.

Program freezes when closing buffered reader. Using forge modding API for minecraft, however I've had this issue before with standalone server side code. This particular code worked fine and then randomly started giving me this issue, not sure how to go about fixing this..

close方法:

public static void closeConnection() {
    if (keepConnection) {
        keepConnection = false;

        try {

            bufferedReader.close();
            printWriter.close();
            socket.close();
        }
        catch (IOException e) {

            e.printStackTrace();
        }

        finally{

            token = null;
        }
    }

}

我有检查以确保确实发生冻结。有任何想法吗?

I have checked to ensure that this is indeed where the freeze is occurring. Any ideas?

推荐答案

不可能。 BufferedReader.close()不会执行任何阻止操作。您甚至不需要它。 PrintWriter.close()将关闭所有内容。

Not possible. BufferedReader.close() doesn't do anything that blocks. You don't even need it. PrintWriter.close() will close everything. Remove it.

唯一可以冻结的操作是关闭 PrintWriter ,这意味着刷新其缓冲区,然后之所以如此,是因为同位体距离读取该程序的输出还有很长一段路要走,或者根本不读取它。

The only operation that can freeze here is closing the PrintWriter, which implies flushing its buffer, and the reason for that must be that the peer is a long way behind reading the output of this program, or isn't reading it at all.

这篇关于程序在bufferedreader关闭时冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆