@Override
public void run() {
while (true) {
try {
if (System.in.read() == 'q') {
// some ations..
}
} catch (IOException e) {
e.printStackTrace();
}
}
Method main implements Runnable and wait key pressed, instead of 'q' must be esc