我正在尝试编写一个循环,直到我在运行应用程序的控制台中键入特定文本.就像是:
while (true) {
try {
System.out.println("Waiting for input...");
Thread.currentThread();
Thread.sleep(2000);
if (input_is_equal_to_STOP){ // if user type STOP in terminal
break;
}
} catch (InterruptedException ie) {
// If this thread was intrrupted by nother thread
}}
Run Code Online (Sandbox Code Playgroud)
而且我希望它在每次通过时写一行,所以我不希望它在一段时间内停止并等待下一个输入.我需要使用多个线程吗?