M
M
mitaichik2017-10-04 01:48:24
Java
mitaichik, 2017-10-04 01:48:24

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

2 answer(s)
S
Sergey Gornostaev, 2017-10-04
@sergey-gornostaev

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 ¯\_(ツ)_/¯

N
Nikita, 2017-10-04
@jkotkot

Google about Object wait/notify, ConcurrentHashMap and all that stuff. In general, Spring is clearly not for you if you don’t understand such basic things yet. Learn the basics first.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question