I have to search for an object: first in a BlockingQueue
, and if it is not there then I need to search in a ConcurrentHashMap
and need to do some operation. This needs to be thread-safe.
Is the code below OK? Does synchronizing on the ConcurrentHashMap
work as expected?
synchronized(blockingQueue){
if(!blockingQueue.contains(element)) {
synchronized(concurrentHashMap) {
//do something
}
}
}