我有这样的问题:程序应该在单独的线程中从控制台读取信息,当我想关闭这个线程时 - 输入保持活动状态。中断线程后如何关闭输入? (programm在Eclipse IDE上运行)
public static void main(final String[] args) {
for (int i = 0; i < 10; i++){
ChatRunner.reader = new BufferedReader(
new InputStreamReader(System.in, ChatRunner.charset));
//some treatment
final Thread input = new Thread(() -> {
try {
ChatRunner.answerFromConsole = ChatRunner.reader.readLine();
} catch (final IOException ioe) {
//
}
});
input.start();
// some treatment
input.interrupt();
}
}
如果我只是关闭BufferedReader,我就无法在循环的下一步中使用它。