i have multithread communication. 1 Thread is dispatching datas to other threads.
Main thread is pushing data:
Main Thread: ConcurrentHashMap map = Glob
You can use BlockingQueue
if you allowed to change your implementation, or use a wait/notify technique to wait and run when occupy.
String value = null;
while(true) {
if((value = map.get(1)) != null) { // VARY IMPORTANT to use get and !=
// work with value
} else {
map.wait(); // should be in a synchronized block.
}
}
and for producer:
String value = "Test";
map.put(1,value);
map.notifyAll(); // or notify().