How to interrupt java.util.Scanner nextLine call
I am using a multi threaded environment were one Thread is constantly listening for user input by repeatedly calling scanner.nextLine() . To end the application, this runloop is stopped by another thread, but the listening thread won't stop until a last user input was made (due to the blocking nature of nextLine() ). Closing the stream seems not to be an option since I am reading from System.in , which returns an InputStream that is not closable. Is there a way to interrupt the blocking of scanner, so that it will return? thanks This article describes an approach to avoiding blocking when