Java keyboard input parsing in a console app

后端 未结 2 572
梦如初夏
梦如初夏 2021-01-05 00:46

I\'ve just started messing around with JLine to parse character input in console mode. It seems to work well, but I\'m wondering:

Is there a nonblocking way in JLine

相关标签:
2条回答
  • 2021-01-05 01:25

    You seem to be on the right track.

    I think the "right" way to do this is a worker thread that pours all the blocking I/O into a non-blocking queue. Hava a look at ConcurrentLinkedQueue from java.util.concurrent.

    0 讨论(0)
  • 2021-01-05 01:41

    You can't use a console to get non-blocking input without native libraries.

    You'll have to write a Swing app and write a KeyListener

    Read this tutorial: http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

    0 讨论(0)
提交回复
热议问题