Is BlockingQueue completely thread safe in Java

前端 未结 5 1718
不思量自难忘°
不思量自难忘° 2020-12-04 22:32

I know that the documentation says that the object is thread safe but does that mean that all access to it from all methods are thread safe? So if I call put()

5条回答
  •  有刺的猬
    2020-12-04 22:41

    That answer is a little strange - for a start, BlockingQueue is an interface so it doesn't have any locks. Implementations such as ArrayBlockingQueue use the same lock for add() and take() so would be fine. Generally, if any implementation is not thread safe then it is a buggy implementation.

提交回复
热议问题