I have a thread working in the background and but it doesn’t always has work to do. I want it to wait for data to be passed by the main thread and then continue working.
At first I thought that’s what wait() and notify() were for but it seems to work the other way around.
How do I do that?
See my comment.
There exist multiple
BlockingQueueimplementations, e.g. a boundedArrayBlockingQueue, an unboundedLinkedBlockingQueue, a hand-offSynchronousQueue, even aPriorityBlockingQueue. AllBlockingDeques andTransferQueues are alsoBlockingQueues 😉