I\'m writing an application that has 5 threads that get some information from web simultaneously and fill 5 different fields in a buffer class.
I need to validate buffer
Another possibility is the CountDownLatch object, which is useful for simple situations : since you know in advance the number of threads, you initialize it with the relevant count, and pass the reference of the object to each thread.
Upon completion of its task, each thread calls CountDownLatch.countDown()
which decrements the internal counter. The main thread, after starting all others, should do the CountDownLatch.await()
blocking call. It will be released as soon as the internal counter has reached 0.
Pay attention that with this object, an InterruptedException
can be thrown as well.