What is the best way to pass information between threads?

前端 未结 3 1699
星月不相逢
星月不相逢 2020-12-13 00:31

I want to be listening to a server while my program is doing other things, when a message is received from the server I want to interpret it.

I know about threading

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 01:22

    Go through some tutorials for understanding Java Threads.

    http://www.journaldev.com/1079/java-thread-tutorial

    Your problem seems to be like producer-consumer model, you can use BlockingQueue to achieve this task easily.

    Java Blocking Queue

提交回复
热议问题