1

I am observing a strange behavior on a Linux box. The code works fine on Win 7. The offending code hangs on xmlToJavaMap.keySet(). Neither of the two log statements are logged!!! No deadlock found in heap dump.

    ConcurrentHashMap<String,String> xmlToJavaMap = ApplicationContext.getBean("map");
    logger.info("before for loop");
    for (String key : xmlToJavaMap.keySet()) {
        logger.info("key: " + key);
        ...
    }   
    logger.info("map processed.");  

Platform: java version "1.7.0_11" Java(TM) SE Runtime Environment (build 1.7.0_11-b21) Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode) Red Hat 4.4.7

Prakash
  • 461
  • 1
  • 5
  • 21
  • You want to check if this code is actually being executed at all or whether your might have a problem somewhere else. ConcurrentHashMap reads are supposed to be non-locking. – pvg Dec 04 '15 at 17:17
  • That's what is puzzling. CHM.keySet() is not expected to block. The execution reaches till before the for loop, then nothing happens. The issue started couple of weeks back in one of the environments. – Prakash Dec 04 '15 at 17:49

3 Answers3

1

Use jps -v to watch your java process. Then use jstack to watch your stack of threads. That could help you find the solution.

Andres
  • 10,561
  • 4
  • 45
  • 63
0

Here is what was actually happening :) xmlToJavaMap.keySet() was actually failing with NoSuchMethod and the thread was terminating. The error stack trace was getting logged in a different log file which was causing the confusion. Once the error was addressed , everything back to normal.

Prakash
  • 461
  • 1
  • 5
  • 21
0

I found the same case, hang at keySet() method. actually the thread exit by NoSuchMethodError error. solution is that just declare

ConcurrentHashMap<String,String> xmlToJavaMap = ApplicationContext.getBean("map");

to

Map<String,String> xmlToJavaMap = ApplicationContext.getBean("map");

or

make sure code and dependency jar is compiled by same jdk version.

the root reason is that "Undefined reference: .. ConcurrentHashMap.keySet()" when building in Java 8 , cause by: in version 7 and 8, keySet() method is not the same return , this error maybe is not in your project's log or console, but in heap. you can dump heap to find java.lang.NoSuchMethodError related to keySet()

DylanZhou
  • 1
  • 1