Best way to handle console commands without stalling?

I’m using the LWJGL for a new project, but it’s not for a game, exactly. The point is that this project is meant to take in lines from the console piped from some other device. It’s not important what the other device is, but the point is that a few times a second this device will write a string to the command line, which is then piped into my program.

What’s the best way to handle these string inputs? Provisionally, I am using the scanner, calling “scanner.nextLine()” to read the next line. The problem is that this will pause the program until a new line is written onto the console, which is NOT what I want.

I would rather have the program run as normally, at 60fps or what have you, and IF a new line was written to the console, to THEN call a method using that new string as input.

What is the best way to implement this?

Thanks