1

can anyone explain me if in java

//Thread 1
BlockingQueue<String> queue = new LinkedBlockingQueue<>();
queue.put("232323232");
.....
//Thread 2
Stream<String> result = queue.stream().takeWhile(predicate);

is thread safe? ... if one thread is puts in queue and another is reading with stream takeWhile the queue data?

simonC
  • 4,101
  • 10
  • 50
  • 78
  • I don't think so, cuz .stream is method of Collection interface it is the same with foreach loop. usage of ConcurrentLinkedQueue must be safe – Dmitrii B Sep 08 '22 at 13:32

0 Answers0