How to avoid busy spinning in Java

前端 未结 4 2166
南旧
南旧 2021-02-09 16:02

I have a multi-threaded application where a thread sends a message to another thread. The waiting thread polls for the message and reacts (locks are handled). Like this:

4条回答
  •  名媛妹妹
    2021-02-09 16:41

    If you can reformulate your problem in terms of task-executor then consider using a SingleThreadExecutor. If you need something more exotic - either a concurrent queue or even wait()/notify().

提交回复
热议问题