I have the following code
public CampaignProcessorEntity processCampaign(CampaignProcessorEntity campaignEnity) {
synchronized(campaignEnity.getHash()) {
....
....
}
}
My code inside synchronised block run for minutes ,my requirement is ,if first thread starts executing the block ,the second one should wait ,only if both hash are same or else continue without synchronisation.I have different instance for each thread.The getHash() method returns new String object everytime.So i had a static map ,which stores the hash as key and value,and second thread on arrival checks the hash map and retrieve the monitor used by first thread ,still it does't wait.