难道Java的事情做异步? [英] Does Java not do things asynchronously?

查看:93
本文介绍了难道Java的事情做异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习Java,我正在读一个教程,说是这样的:

I am trying to learn Java, I was reading a tutorial that said something like this:

while (N <= 0) {
           TextIO.put("The starting point must be positive. Please try again: ");
           N = TextIO.getlnInt();
        }

好像当你要求用户输入其挂起,直到响应收到?我习惯了这些事情发生异步。这是正常的Java?或者你可以两者都做?

It seems like when you ask the user for input it suspends until the response is recieved? I am used to these things happening asynchronously. Is this normal for Java? or can you do both?

感谢。

推荐答案

我不熟悉的 TEXTIO 库,但是打电话时的 InputStream.read(),即当使用 System.in.read(),它会阻止,直到在输入数据可用。这使得同步

I'm not familiar with that TextIO library, but when calling InputStream.read(), i.e. when using System.in.read(), it will block until input data is available. This makes it synchronous.

您可以用另一个线程来捕获输入避免这种情况(即让异步)。

You can avoid this (i.e. make it asynchronous) by using another thread to capture input.

这篇关于难道Java的事情做异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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