gpt4 book ai didi

java - 流 readLine 以中断关闭

转载 作者:行者123 更新时间:2023-12-04 05:05:06 25 4
gpt4 key购买 nike

我有一个线程,它从 getInputStream 读取输入的 Process .它等待 readLine。

BufferedReader read = new BufferedReader(new InputStreamReader(process.getInputStream));
while(!Thread.currentThread().isInterrupted()){
String s = read.readLine();
process(s);
}

但事实证明, readLine不响应中断状态。因此,在关闭期间,它不会让 JVM 关闭。在浏览源代码时,看起来他们只是轮询直到有 \n行终止符。

任何替代方案或黑客?

PS:它是 How to interrupt BufferedReader's readLine 的副本.因此我关闭它

最佳答案

不应该是:

while(!Thread.currentThread().isInterrupted()){

关于java - 流 readLine 以中断关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15615214/

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