I have this container
private ConcurrentMap<Integer,SortedMap<Long,Object>> users;
Which gets initialized in constructor users = new ConcurrentHashMap<>();
and for each user it gets new ConcurrentSkipListMap<>()
I have this method which is called over and over again in threadpool
private void process(Object obj){
// SOME CODE
SortedMap<Long,Object> q = users.get( obj.userId);
logger.debug("SECTION 1");
q.headMap( someNumber ).clear();
logger.debug("SECTION 2");
q.put( obj.someId, obj );
logger.debug("SECTION 3");
}
this method is called using executorService = Executors.newScheduledThreadPool(8);
executorService.execute(new Runnable() {
@Override
public void run() {
process(obj);
}
});
sometimes it works fine but sometimes (I suppose on high load) for some user process methods (all calls) get stuck and never outputs SECTION 2
and if I swap q.headMap( someNumber ).clear();
and q.put( obj.someId, obj );
it still doesn't output SECTION 2
I also tried LinkedBlockingQueue
instead of ConcurrentSkipListMap
but I have same issue
it looks like a deadlock but I'm not using any synchronized statement on that structure.
please share your idea if you have one