java - How to make scanner accept constant input -
I am very new to Java, and would like to know that whenever I offer something to it, the scanner gets input How to approve everything is still working. I have tried to use the loop for a while like this.
scanner scanner = new scanner (System.in); While (scanner.hasNext ()) {string next = scanner.xt (); }
now accepts this input all the time, but nothing else is working. I have tried Google search but I have not been able to help. I know that I will go Being told to read the docs, but I do not know what I should read there.
Actually what I am trying to do is a simple command system for me. I currently have this
scanner scanner = new scanner (System.in); String next = scanner.xt (); If (next.startsWith ("-") {string [] commandline = next. Split ("-"); String command = command line [1]; If (command.equalsIgnoreCase ("start")) {if (running!) {Timer.scheduleAtFixedRate (New Listen (), 0, 5000); System.out.println ("Started."); } Else {System.err.println ("The job is already running!"); }} And if (command.equalsIgnoreCase ("end")) {if (running) {timer.cancel (); System.out.println ("Work Closed."); } And {System.err.println ("the job is not running!"); }} And if (command.equalsIgnoreCase ("exit")) {if (running) {timer.cancel (); } System.exit (0); }}
Any help is appreciated. Thank you. As you have seen, the current thread can not do anything while waiting for the terminal input.
The solution to this problem is multi-threading, which is described in the section.
... concurrency tells how to write applications that work together multiple ... In this lesson the original concurrency support for the platform has been introduced and some high- Level APIs in the java.util.concurrent package.
Comments
Post a Comment