[solved] Reading commands without waiting

I’m trying to read commands the user enters into cmd, but the only way I’ve been able to implement it is like this:

Scanner scanner = new Scanner(System.in);
String command = "";
while(true){
    command = scanner.nextLine();
    doCommand(command);
}

This results in the application waiting for the next command from the user, it can’t do anything else. Is there another way I can do this?