Answer the question
In order to leave comments, you need to log in
How to pause a thread until a specific event?
I have a stream. He needs to stop at a certain moment and wait until some event occurs (or rather, some element is not added to the HashMap, the addition goes in other threads)
Tell me, how is this usually done? I use Java 8 + Spring
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
First, it is possible that the answer is contained in the question itself. Spring has high-level abstractions that eliminate the need for explicit threading in many cases - events and asynchronous methods. Secondly, as Nikita already wrote , there are many ways to synchronize threads, in order to give the correct answer, you need to know your algorithm. Maybe you need a CyclicBarrier, or maybe it would be more efficient to replace HashMap with BlockingQueue ¯\_(ツ)_/¯
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question